OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_GUESTVIEW_WEBVIEW_WEBVIEW_GUEST_H_ | 5 #ifndef CHROME_BROWSER_GUESTVIEW_WEBVIEW_WEBVIEW_GUEST_H_ |
6 #define CHROME_BROWSER_GUESTVIEW_WEBVIEW_WEBVIEW_GUEST_H_ | 6 #define CHROME_BROWSER_GUESTVIEW_WEBVIEW_WEBVIEW_GUEST_H_ |
7 | 7 |
8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
9 #include "chrome/browser/extensions/tab_helper.h" | 9 #include "chrome/browser/extensions/tab_helper.h" |
10 #include "chrome/browser/guestview/guestview.h" | 10 #include "chrome/browser/guestview/guestview.h" |
| 11 #include "content/public/browser/notification_registrar.h" |
11 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 class ScriptExecutor; | 15 class ScriptExecutor; |
15 } // namespace extensions | 16 } // namespace extensions |
16 | 17 |
17 // A WebViewGuest is a WebContentsObserver on the guest WebContents of a | 18 // A WebViewGuest is a WebContentsObserver on the guest WebContents of a |
18 // <webview> tag. It provides the browser-side implementation of the <webview> | 19 // <webview> tag. It provides the browser-side implementation of the <webview> |
19 // API and manages the lifetime of <webview> extension events. WebViewGuest is | 20 // API and manages the lifetime of <webview> extension events. WebViewGuest is |
20 // created on attachment. That is, when a guest WebContents is associated with | 21 // created on attachment. That is, when a guest WebContents is associated with |
21 // a particular embedder WebContents. This happens on either initial navigation | 22 // a particular embedder WebContents. This happens on either initial navigation |
22 // or through the use of the New Window API, when a new window is attached to | 23 // or through the use of the New Window API, when a new window is attached to |
23 // a particular <webview>. | 24 // a particular <webview>. |
24 class WebViewGuest : public GuestView, | 25 class WebViewGuest : public GuestView, |
| 26 public content::NotificationObserver, |
25 public content::WebContentsObserver { | 27 public content::WebContentsObserver { |
26 public: | 28 public: |
27 explicit WebViewGuest(content::WebContents* guest_web_contents); | 29 explicit WebViewGuest(content::WebContents* guest_web_contents); |
28 | 30 |
29 static WebViewGuest* From(int embedder_process_id, int instance_id); | 31 static WebViewGuest* From(int embedder_process_id, int instance_id); |
30 | 32 |
31 // GuestView implementation. | 33 // GuestView implementation. |
32 virtual void Attach(content::WebContents* embedder_web_contents, | 34 virtual void Attach(content::WebContents* embedder_web_contents, |
33 const std::string& extension_id, | 35 const std::string& extension_id, |
34 int view_instance_id, | 36 int view_instance_id, |
35 const base::DictionaryValue& args) OVERRIDE; | 37 const base::DictionaryValue& args) OVERRIDE; |
36 virtual GuestView::Type GetViewType() const OVERRIDE; | 38 virtual GuestView::Type GetViewType() const OVERRIDE; |
37 virtual WebViewGuest* AsWebView() OVERRIDE; | 39 virtual WebViewGuest* AsWebView() OVERRIDE; |
38 virtual AdViewGuest* AsAdView() OVERRIDE; | 40 virtual AdViewGuest* AsAdView() OVERRIDE; |
39 | 41 |
| 42 // NotificationObserver implementation. |
| 43 virtual void Observe(int type, |
| 44 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) OVERRIDE; |
| 46 |
40 // If possible, navigate the guest to |relative_index| entries away from the | 47 // If possible, navigate the guest to |relative_index| entries away from the |
41 // current navigation entry. | 48 // current navigation entry. |
42 void Go(int relative_index); | 49 void Go(int relative_index); |
43 | 50 |
44 extensions::ScriptExecutor* script_executor() { | 51 extensions::ScriptExecutor* script_executor() { |
45 return script_executor_.get(); | 52 return script_executor_.get(); |
46 } | 53 } |
47 | 54 |
48 private: | 55 private: |
49 virtual ~WebViewGuest(); | 56 virtual ~WebViewGuest(); |
50 | 57 |
| 58 // WebContentsObserver implementation. |
51 virtual void DidCommitProvisionalLoadForFrame( | 59 virtual void DidCommitProvisionalLoadForFrame( |
52 int64 frame_id, | 60 int64 frame_id, |
53 bool is_main_frame, | 61 bool is_main_frame, |
54 const GURL& url, | 62 const GURL& url, |
55 content::PageTransition transition_type, | 63 content::PageTransition transition_type, |
56 content::RenderViewHost* render_view_host) OVERRIDE; | 64 content::RenderViewHost* render_view_host) OVERRIDE; |
57 virtual void DidStopLoading( | 65 virtual void DidStopLoading( |
58 content::RenderViewHost* render_view_host) OVERRIDE; | 66 content::RenderViewHost* render_view_host) OVERRIDE; |
59 virtual void WebContentsDestroyed( | 67 virtual void WebContentsDestroyed( |
60 content::WebContents* web_contents) OVERRIDE; | 68 content::WebContents* web_contents) OVERRIDE; |
61 | 69 |
| 70 // Called after the load handler is called in the guest's main frame. |
| 71 void LoadHandlerCalled(); |
| 72 |
62 void AddWebViewToExtensionRendererState(); | 73 void AddWebViewToExtensionRendererState(); |
63 static void RemoveWebViewFromExtensionRendererState( | 74 static void RemoveWebViewFromExtensionRendererState( |
64 content::WebContents* web_contents); | 75 content::WebContents* web_contents); |
65 | 76 |
66 ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 77 ObserverList<extensions::TabHelper::ScriptExecutionObserver> |
67 script_observers_; | 78 script_observers_; |
68 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 79 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
69 | 80 |
| 81 content::NotificationRegistrar notification_registrar_; |
| 82 |
70 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 83 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
71 }; | 84 }; |
72 | 85 |
73 #endif // CHROME_BROWSER_GUESTVIEW_WEBVIEW_WEBVIEW_GUEST_H_ | 86 #endif // CHROME_BROWSER_GUESTVIEW_WEBVIEW_WEBVIEW_GUEST_H_ |
OLD | NEW |