OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/common/view_type.h" |
14 #include "content/public/renderer/render_view_observer.h" | 15 #include "content/public/renderer/render_view_observer.h" |
15 #include "content/public/renderer/render_view_observer_tracker.h" | 16 #include "content/public/renderer/render_view_observer_tracker.h" |
16 #include "content/public/common/view_type.h" | |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" |
18 | 18 |
19 class ExtensionDispatcher; | 19 class ExtensionDispatcher; |
20 class GURL; | 20 class GURL; |
21 class SkBitmap; | 21 class SkBitmap; |
22 struct ExtensionMsg_ExecuteCode_Params; | 22 struct ExtensionMsg_ExecuteCode_Params; |
23 struct WebApplicationInfo; | 23 struct WebApplicationInfo; |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 class ListValue; | 26 class ListValue; |
27 } | 27 } |
28 | 28 |
29 namespace webkit_glue { | 29 namespace webkit_glue { |
30 class ResourceFetcher; | 30 class ResourceFetcher; |
31 class ImageResourceFetcher; | 31 class ImageResourceFetcher; |
32 } | 32 } |
33 | 33 |
34 // RenderView-level plumbing for extension features. | 34 // RenderView-level plumbing for extension features. |
35 class ExtensionHelper | 35 class ExtensionHelper |
36 : public content::RenderViewObserver, | 36 : public content::RenderViewObserver, |
37 public content::RenderViewObserverTracker<ExtensionHelper> { | 37 public content::RenderViewObserverTracker<ExtensionHelper> { |
38 public: | 38 public: |
39 // Returns a list of extension RenderViews that match the given filter | 39 // Returns a list of extension RenderViews that match the given filter |
40 // criteria. If |browser_window_id| is not extension_misc::kUnknownWindowId, | 40 // criteria. If |browser_window_id| is not extension_misc::kUnknownWindowId, |
41 // the list is restricted to views in that browser window. | 41 // the list is restricted to views in that browser window. |
42 static std::vector<content::RenderView*> GetExtensionViews( | 42 static std::vector<content::RenderView*> GetExtensionViews( |
43 const std::string& extension_id, | 43 const std::string& extension_id, |
44 int browser_window_id, | 44 int browser_window_id, |
45 content::ViewType view_type); | 45 chrome::ViewType view_type); |
46 | 46 |
47 // Returns the given extension's background page, or NULL if none. | 47 // Returns the given extension's background page, or NULL if none. |
48 static content::RenderView* GetBackgroundPage( | 48 static content::RenderView* GetBackgroundPage( |
49 const std::string& extension_id); | 49 const std::string& extension_id); |
50 | 50 |
51 ExtensionHelper(content::RenderView* render_view, | 51 ExtensionHelper(content::RenderView* render_view, |
52 ExtensionDispatcher* extension_dispatcher); | 52 ExtensionDispatcher* extension_dispatcher); |
53 virtual ~ExtensionHelper(); | 53 virtual ~ExtensionHelper(); |
54 | 54 |
55 // Starts installation of the page in the specified frame as a web app. The | 55 // Starts installation of the page in the specified frame as a web app. The |
56 // page must link to an external 'definition file'. This is different from | 56 // page must link to an external 'definition file'. This is different from |
57 // the 'application shortcuts' feature where we pull the application | 57 // the 'application shortcuts' feature where we pull the application |
58 // definition out of optional meta tags in the page. | 58 // definition out of optional meta tags in the page. |
59 bool InstallWebApplicationUsingDefinitionFile(WebKit::WebFrame* frame, | 59 bool InstallWebApplicationUsingDefinitionFile(WebKit::WebFrame* frame, |
60 string16* error); | 60 string16* error); |
61 | 61 |
62 int browser_window_id() const { return browser_window_id_; } | 62 int browser_window_id() const { return browser_window_id_; } |
63 content::ViewType view_type() const { return view_type_; } | 63 chrome::ViewType view_type() const { return view_type_; } |
64 | 64 |
65 private: | 65 private: |
66 // RenderViewObserver implementation. | 66 // RenderViewObserver implementation. |
67 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 67 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
68 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE; | 68 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE; |
69 virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE; | 69 virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE; |
70 virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) OVERRIDE; | 70 virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) OVERRIDE; |
71 virtual void DidStartProvisionalLoad(WebKit::WebFrame* frame) OVERRIDE; | 71 virtual void DidStartProvisionalLoad(WebKit::WebFrame* frame) OVERRIDE; |
72 virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE; | 72 virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE; |
73 virtual void DidCreateDataSource(WebKit::WebFrame* frame, | 73 virtual void DidCreateDataSource(WebKit::WebFrame* frame, |
(...skipping 10 matching lines...) Expand all Loading... |
84 void OnExtensionDispatchOnConnect(int target_port_id, | 84 void OnExtensionDispatchOnConnect(int target_port_id, |
85 const std::string& channel_name, | 85 const std::string& channel_name, |
86 const std::string& tab_json, | 86 const std::string& tab_json, |
87 const std::string& source_extension_id, | 87 const std::string& source_extension_id, |
88 const std::string& target_extension_id); | 88 const std::string& target_extension_id); |
89 void OnExtensionDeliverMessage(int target_port_id, | 89 void OnExtensionDeliverMessage(int target_port_id, |
90 const std::string& message); | 90 const std::string& message); |
91 void OnExtensionDispatchOnDisconnect(int port_id, bool connection_error); | 91 void OnExtensionDispatchOnDisconnect(int port_id, bool connection_error); |
92 void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); | 92 void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); |
93 void OnGetApplicationInfo(int page_id); | 93 void OnGetApplicationInfo(int page_id); |
94 void OnNotifyRendererViewType(content::ViewType view_type); | 94 void OnNotifyRendererViewType(chrome::ViewType view_type); |
95 void OnUpdateBrowserWindowId(int window_id); | 95 void OnUpdateBrowserWindowId(int window_id); |
96 | 96 |
97 // Callback triggered when we finish downloading the application definition | 97 // Callback triggered when we finish downloading the application definition |
98 // file. | 98 // file. |
99 void DidDownloadApplicationDefinition(const WebKit::WebURLResponse& response, | 99 void DidDownloadApplicationDefinition(const WebKit::WebURLResponse& response, |
100 const std::string& data); | 100 const std::string& data); |
101 | 101 |
102 // Callback triggered after each icon referenced by the application definition | 102 // Callback triggered after each icon referenced by the application definition |
103 // is downloaded. | 103 // is downloaded. |
104 void DidDownloadApplicationIcon(webkit_glue::ImageResourceFetcher* fetcher, | 104 void DidDownloadApplicationIcon(webkit_glue::ImageResourceFetcher* fetcher, |
(...skipping 15 matching lines...) Expand all Loading... |
120 // Used to download the icons for an application. | 120 // Used to download the icons for an application. |
121 typedef std::vector<linked_ptr<webkit_glue::ImageResourceFetcher> > | 121 typedef std::vector<linked_ptr<webkit_glue::ImageResourceFetcher> > |
122 ImageResourceFetcherList; | 122 ImageResourceFetcherList; |
123 ImageResourceFetcherList app_icon_fetchers_; | 123 ImageResourceFetcherList app_icon_fetchers_; |
124 | 124 |
125 // The number of app icon requests outstanding. When this reaches zero, we're | 125 // The number of app icon requests outstanding. When this reaches zero, we're |
126 // done processing an app definition file. | 126 // done processing an app definition file. |
127 int pending_app_icon_requests_; | 127 int pending_app_icon_requests_; |
128 | 128 |
129 // Type of view attached with RenderView. | 129 // Type of view attached with RenderView. |
130 content::ViewType view_type_; | 130 chrome::ViewType view_type_; |
131 | 131 |
132 // Id number of browser window which RenderView is attached to. | 132 // Id number of browser window which RenderView is attached to. |
133 int browser_window_id_; | 133 int browser_window_id_; |
134 | 134 |
135 DISALLOW_COPY_AND_ASSIGN(ExtensionHelper); | 135 DISALLOW_COPY_AND_ASSIGN(ExtensionHelper); |
136 }; | 136 }; |
137 | 137 |
138 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ | 138 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_HELPER_H_ |
OLD | NEW |