• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "tests/cefclient/browser/browser_window.h"
6 
7 #include "include/base/cef_callback.h"
8 #include "tests/shared/browser/main_message_loop.h"
9 
10 namespace client {
11 
BrowserWindow(Delegate * delegate)12 BrowserWindow::BrowserWindow(Delegate* delegate)
13     : delegate_(delegate), is_closing_(false) {
14   DCHECK(delegate_);
15 }
16 
SetDeviceScaleFactor(float device_scale_factor)17 void BrowserWindow::SetDeviceScaleFactor(float device_scale_factor) {}
18 
GetDeviceScaleFactor() const19 float BrowserWindow::GetDeviceScaleFactor() const {
20   return 1.0f;
21 }
22 
GetBrowser() const23 CefRefPtr<CefBrowser> BrowserWindow::GetBrowser() const {
24   REQUIRE_MAIN_THREAD();
25   return browser_;
26 }
27 
IsClosing() const28 bool BrowserWindow::IsClosing() const {
29   REQUIRE_MAIN_THREAD();
30   return is_closing_;
31 }
32 
OnBrowserCreated(CefRefPtr<CefBrowser> browser)33 void BrowserWindow::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
34   REQUIRE_MAIN_THREAD();
35   DCHECK(!browser_);
36   browser_ = browser;
37 
38   delegate_->OnBrowserCreated(browser);
39 }
40 
OnBrowserClosing(CefRefPtr<CefBrowser> browser)41 void BrowserWindow::OnBrowserClosing(CefRefPtr<CefBrowser> browser) {
42   REQUIRE_MAIN_THREAD();
43   DCHECK_EQ(browser->GetIdentifier(), browser_->GetIdentifier());
44   is_closing_ = true;
45 
46   delegate_->OnBrowserWindowClosing();
47 }
48 
OnBrowserClosed(CefRefPtr<CefBrowser> browser)49 void BrowserWindow::OnBrowserClosed(CefRefPtr<CefBrowser> browser) {
50   REQUIRE_MAIN_THREAD();
51   if (browser_.get()) {
52     DCHECK_EQ(browser->GetIdentifier(), browser_->GetIdentifier());
53     browser_ = nullptr;
54   }
55 
56   client_handler_->DetachDelegate();
57   client_handler_ = nullptr;
58 
59   // |this| may be deleted.
60   delegate_->OnBrowserWindowDestroyed();
61 }
62 
OnSetAddress(const std::string & url)63 void BrowserWindow::OnSetAddress(const std::string& url) {
64   REQUIRE_MAIN_THREAD();
65   delegate_->OnSetAddress(url);
66 }
67 
OnSetTitle(const std::string & title)68 void BrowserWindow::OnSetTitle(const std::string& title) {
69   REQUIRE_MAIN_THREAD();
70   delegate_->OnSetTitle(title);
71 }
72 
OnSetFullscreen(bool fullscreen)73 void BrowserWindow::OnSetFullscreen(bool fullscreen) {
74   REQUIRE_MAIN_THREAD();
75   delegate_->OnSetFullscreen(fullscreen);
76 }
77 
OnAutoResize(const CefSize & new_size)78 void BrowserWindow::OnAutoResize(const CefSize& new_size) {
79   REQUIRE_MAIN_THREAD();
80   delegate_->OnAutoResize(new_size);
81 }
82 
OnSetLoadingState(bool isLoading,bool canGoBack,bool canGoForward)83 void BrowserWindow::OnSetLoadingState(bool isLoading,
84                                       bool canGoBack,
85                                       bool canGoForward) {
86   REQUIRE_MAIN_THREAD();
87   delegate_->OnSetLoadingState(isLoading, canGoBack, canGoForward);
88 }
89 
OnSetDraggableRegions(const std::vector<CefDraggableRegion> & regions)90 void BrowserWindow::OnSetDraggableRegions(
91     const std::vector<CefDraggableRegion>& regions) {
92   REQUIRE_MAIN_THREAD();
93   delegate_->OnSetDraggableRegions(regions);
94 }
95 
96 }  // namespace client
97