| 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_WEBVIEW_WEBVIEW_GUEST_H_ | 5 #ifndef CHROME_BROWSER_WEBVIEW_WEBVIEW_GUEST_H_ |
| 6 #define CHROME_BROWSER_WEBVIEW_WEBVIEW_GUEST_H_ | 6 #define CHROME_BROWSER_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 "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 class ScriptExecutor; | 13 class ScriptExecutor; |
| 14 } // namespace extensions | 14 } // namespace extensions |
| 15 | 15 |
| 16 namespace chrome { | |
| 17 | |
| 18 // A WebViewGuest is a WebContentsObserver on the guest WebContents of a | 16 // A WebViewGuest is a WebContentsObserver on the guest WebContents of a |
| 19 // <webview> tag. It provides the browser-side implementation of the <webview> | 17 // <webview> tag. It provides the browser-side implementation of the <webview> |
| 20 // API and manages the lifetime of <webview> extension events. WebViewGuest is | 18 // API and manages the lifetime of <webview> extension events. WebViewGuest is |
| 21 // created on attachment. That is, when a guest WebContents is associated with | 19 // created on attachment. That is, when a guest WebContents is associated with |
| 22 // a particular embedder WebContents. This happens on either initial navigation | 20 // a particular embedder WebContents. This happens on either initial navigation |
| 23 // or through the use of the New Window API, when a new window is attached to | 21 // or through the use of the New Window API, when a new window is attached to |
| 24 // a particular <webview>. | 22 // a particular <webview>. |
| 25 class WebViewGuest : public content::WebContentsObserver { | 23 class WebViewGuest : public content::WebContentsObserver { |
| 26 public: | 24 public: |
| 27 WebViewGuest(content::WebContents* guest_web_contents, | 25 WebViewGuest(content::WebContents* guest_web_contents, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 } | 39 } |
| 42 | 40 |
| 43 int instance_id() const { return webview_instance_id_; } | 41 int instance_id() const { return webview_instance_id_; } |
| 44 | 42 |
| 45 extensions::ScriptExecutor* script_executor() { | 43 extensions::ScriptExecutor* script_executor() { |
| 46 return script_executor_.get(); | 44 return script_executor_.get(); |
| 47 } | 45 } |
| 48 | 46 |
| 49 private: | 47 private: |
| 50 virtual ~WebViewGuest(); | 48 virtual ~WebViewGuest(); |
| 49 |
| 50 void DispatchEvent(const std::string& event_name, |
| 51 scoped_ptr<DictionaryValue> event); |
| 52 |
| 53 virtual void DidCommitProvisionalLoadForFrame( |
| 54 int64 frame_id, |
| 55 bool is_main_frame, |
| 56 const GURL& url, |
| 57 content::PageTransition transition_type, |
| 58 content::RenderViewHost* render_view_host) OVERRIDE; |
| 51 virtual void WebContentsDestroyed( | 59 virtual void WebContentsDestroyed( |
| 52 content::WebContents* web_contents) OVERRIDE; | 60 content::WebContents* web_contents) OVERRIDE; |
| 53 | 61 |
| 54 void AddWebViewToExtensionRendererState(); | 62 void AddWebViewToExtensionRendererState(); |
| 55 static void RemoveWebViewFromExtensionRendererState( | 63 static void RemoveWebViewFromExtensionRendererState( |
| 56 content::WebContents* web_contents); | 64 content::WebContents* web_contents); |
| 57 | 65 |
| 58 content::WebContents* embedder_web_contents_; | 66 content::WebContents* embedder_web_contents_; |
| 59 const std::string extension_id_; | 67 const std::string extension_id_; |
| 60 const int embedder_render_process_id_; | 68 const int embedder_render_process_id_; |
| 61 // Profile and instance ID are cached here because |web_contents()| is | 69 // Profile and instance ID are cached here because |web_contents()| is |
| 62 // null on destruction. | 70 // null on destruction. |
| 63 void* profile_; | 71 void* profile_; |
| 64 // |guest_instance_id_| is a profile-wide unique identifier for a guest | 72 // |guest_instance_id_| is a profile-wide unique identifier for a guest |
| 65 // WebContents. | 73 // WebContents. |
| 66 const int guest_instance_id_; | 74 const int guest_instance_id_; |
| 67 // |webview_instance_id_| is an identifier that's unique within a particular | 75 // |webview_instance_id_| is an identifier that's unique within a particular |
| 68 // embedder RenderView for a particular <webview> instance. | 76 // embedder RenderView for a particular <webview> instance. |
| 69 const int webview_instance_id_; | 77 const int webview_instance_id_; |
| 70 | 78 |
| 71 ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 79 ObserverList<extensions::TabHelper::ScriptExecutionObserver> |
| 72 script_observers_; | 80 script_observers_; |
| 73 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 81 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
| 74 | 82 |
| 75 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 83 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
| 76 }; | 84 }; |
| 77 | 85 |
| 78 } // namespace chrome | |
| 79 | |
| 80 #endif // CHROME_BROWSER_WEBVIEW_WEBVIEW_GUEST_H_ | 86 #endif // CHROME_BROWSER_WEBVIEW_WEBVIEW_GUEST_H_ |
| OLD | NEW |