OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "chrome/browser/extensions/tab_helper.h" | 11 #include "chrome/browser/extensions/tab_helper.h" |
12 #include "chrome/browser/guest_view/guest_view.h" | 12 #include "chrome/browser/guest_view/guest_view.h" |
13 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" | 13 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" |
14 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" | 14 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" |
| 15 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
15 #include "chrome/common/extensions/api/webview.h" | 16 #include "chrome/common/extensions/api/webview.h" |
16 #include "content/public/browser/javascript_dialog_manager.h" | 17 #include "content/public/browser/javascript_dialog_manager.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
19 #include "third_party/WebKit/public/web/WebFindOptions.h" | 20 #include "third_party/WebKit/public/web/WebFindOptions.h" |
20 | 21 |
21 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
22 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 23 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
23 #endif | 24 #endif |
24 | 25 |
(...skipping 14 matching lines...) Expand all Loading... |
39 // <webview> tag. It provides the browser-side implementation of the <webview> | 40 // <webview> tag. It provides the browser-side implementation of the <webview> |
40 // API and manages the lifetime of <webview> extension events. WebViewGuest is | 41 // API and manages the lifetime of <webview> extension events. WebViewGuest is |
41 // created on attachment. That is, when a guest WebContents is associated with | 42 // created on attachment. That is, when a guest WebContents is associated with |
42 // a particular embedder WebContents. This happens on either initial navigation | 43 // a particular embedder WebContents. This happens on either initial navigation |
43 // or through the use of the New Window API, when a new window is attached to | 44 // or through the use of the New Window API, when a new window is attached to |
44 // a particular <webview>. | 45 // a particular <webview>. |
45 class WebViewGuest : public GuestView<WebViewGuest>, | 46 class WebViewGuest : public GuestView<WebViewGuest>, |
46 public content::NotificationObserver, | 47 public content::NotificationObserver, |
47 public content::WebContentsObserver { | 48 public content::WebContentsObserver { |
48 public: | 49 public: |
49 WebViewGuest(content::WebContents* guest_web_contents, | 50 WebViewGuest(int guest_instance_id, |
50 const std::string& embedder_extension_id, | 51 content::WebContents* guest_web_contents, |
51 const base::WeakPtr<GuestViewBase>& opener); | 52 const std::string& embedder_extension_id); |
52 | 53 |
53 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a | 54 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a |
54 // WebViewGuest. | 55 // WebViewGuest. |
55 static int GetViewInstanceId(content::WebContents* contents); | 56 static int GetViewInstanceId(content::WebContents* contents); |
56 static const char Type[]; | 57 static const char Type[]; |
57 | 58 |
58 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; | 59 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; |
59 // Shows the context menu for the guest. | 60 // Shows the context menu for the guest. |
60 // |items| acts as a filter. This restricts the current context's default | 61 // |items| acts as a filter. This restricts the current context's default |
61 // menu items to contain only the items from |items|. | 62 // menu items to contain only the items from |items|. |
(...skipping 20 matching lines...) Expand all Loading... |
82 virtual void FindReply(int request_id, | 83 virtual void FindReply(int request_id, |
83 int number_of_matches, | 84 int number_of_matches, |
84 const gfx::Rect& selection_rect, | 85 const gfx::Rect& selection_rect, |
85 int active_match_ordinal, | 86 int active_match_ordinal, |
86 bool final_update) OVERRIDE; | 87 bool final_update) OVERRIDE; |
87 virtual void GuestProcessGone(base::TerminationStatus status) OVERRIDE; | 88 virtual void GuestProcessGone(base::TerminationStatus status) OVERRIDE; |
88 virtual bool HandleKeyboardEvent( | 89 virtual bool HandleKeyboardEvent( |
89 const content::NativeWebKeyboardEvent& event) OVERRIDE; | 90 const content::NativeWebKeyboardEvent& event) OVERRIDE; |
90 virtual bool IsDragAndDropEnabled() OVERRIDE; | 91 virtual bool IsDragAndDropEnabled() OVERRIDE; |
91 virtual bool IsOverridingUserAgent() const OVERRIDE; | 92 virtual bool IsOverridingUserAgent() const OVERRIDE; |
92 virtual void LoadAbort(bool is_top_level, | |
93 const GURL& url, | |
94 const std::string& error_type) OVERRIDE; | |
95 virtual void RendererResponsive() OVERRIDE; | 93 virtual void RendererResponsive() OVERRIDE; |
96 virtual void RendererUnresponsive() OVERRIDE; | 94 virtual void RendererUnresponsive() OVERRIDE; |
97 virtual void RequestPermission( | |
98 BrowserPluginPermissionType permission_type, | |
99 const base::DictionaryValue& request_info, | |
100 const PermissionResponseCallback& callback, | |
101 bool allowed_by_default) OVERRIDE; | |
102 virtual GURL ResolveURL(const std::string& src) OVERRIDE; | |
103 virtual void SizeChanged(const gfx::Size& old_size, const gfx::Size& new_size) | 95 virtual void SizeChanged(const gfx::Size& old_size, const gfx::Size& new_size) |
104 OVERRIDE; | 96 OVERRIDE; |
105 virtual void RequestMediaAccessPermission( | 97 virtual void RequestMediaAccessPermission( |
106 const content::MediaStreamRequest& request, | 98 const content::MediaStreamRequest& request, |
107 const content::MediaResponseCallback& callback) OVERRIDE; | 99 const content::MediaResponseCallback& callback) OVERRIDE; |
108 virtual void CanDownload(const std::string& request_method, | 100 virtual void CanDownload(const std::string& request_method, |
109 const GURL& url, | 101 const GURL& url, |
110 const base::Callback<void(bool)>& callback) OVERRIDE; | 102 const base::Callback<void(bool)>& callback) OVERRIDE; |
111 virtual void RequestPointerLockPermission( | 103 virtual void RequestPointerLockPermission( |
112 bool user_gesture, | 104 bool user_gesture, |
113 bool last_unlocked_by_target, | 105 bool last_unlocked_by_target, |
114 const base::Callback<void(bool)>& callback) OVERRIDE; | 106 const base::Callback<void(bool)>& callback) OVERRIDE; |
115 virtual content::JavaScriptDialogManager* | 107 virtual content::JavaScriptDialogManager* |
116 GetJavaScriptDialogManager() OVERRIDE; | 108 GetJavaScriptDialogManager() OVERRIDE; |
| 109 virtual void NavigateGuest(const std::string& src) OVERRIDE; |
| 110 virtual void Destroy() OVERRIDE; |
| 111 virtual void AddNewContents(content::WebContents* source, |
| 112 content::WebContents* new_contents, |
| 113 WindowOpenDisposition disposition, |
| 114 const gfx::Rect& initial_pos, |
| 115 bool user_gesture, |
| 116 bool* was_blocked) OVERRIDE; |
| 117 virtual content::WebContents* OpenURLFromTab( |
| 118 content::WebContents* source, |
| 119 const content::OpenURLParams& params) OVERRIDE; |
| 120 virtual void WebContentsCreated(content::WebContents* source_contents, |
| 121 int opener_render_frame_id, |
| 122 const base::string16& frame_name, |
| 123 const GURL& target_url, |
| 124 content::WebContents* new_contents) OVERRIDE; |
117 | 125 |
118 // NotificationObserver implementation. | 126 // NotificationObserver implementation. |
119 virtual void Observe(int type, | 127 virtual void Observe(int type, |
120 const content::NotificationSource& source, | 128 const content::NotificationSource& source, |
121 const content::NotificationDetails& details) OVERRIDE; | 129 const content::NotificationDetails& details) OVERRIDE; |
122 | 130 |
123 // Set the zoom factor. | 131 // Set the zoom factor. |
124 virtual void SetZoom(double zoom_factor) OVERRIDE; | 132 virtual void SetZoom(double zoom_factor) OVERRIDE; |
125 | 133 |
126 // Returns the current zoom factor. | 134 // Returns the current zoom factor. |
127 double GetZoom(); | 135 double GetZoom(); |
128 | 136 |
129 // Begin or continue a find request. | 137 // Begin or continue a find request. |
130 void Find(const base::string16& search_text, | 138 void Find(const base::string16& search_text, |
131 const blink::WebFindOptions& options, | 139 const blink::WebFindOptions& options, |
132 scoped_refptr<extensions::WebviewFindFunction> find_function); | 140 scoped_refptr<extensions::WebviewFindFunction> find_function); |
133 | 141 |
134 // Conclude a find request to clear highlighting. | 142 // Conclude a find request to clear highlighting. |
135 void StopFinding(content::StopFindAction); | 143 void StopFinding(content::StopFindAction); |
136 | 144 |
137 // If possible, navigate the guest to |relative_index| entries away from the | 145 // If possible, navigate the guest to |relative_index| entries away from the |
138 // current navigation entry. | 146 // current navigation entry. |
139 void Go(int relative_index); | 147 void Go(int relative_index); |
140 | 148 |
141 // Reload the guest. | 149 // Reload the guest. |
142 void Reload(); | 150 void Reload(); |
143 | 151 |
| 152 typedef base::Callback<void(bool /* allow */, |
| 153 const std::string& /* user_input */)> |
| 154 PermissionResponseCallback; |
| 155 int RequestPermission( |
| 156 WebViewPermissionType permission_type, |
| 157 const base::DictionaryValue& request_info, |
| 158 const PermissionResponseCallback& callback, |
| 159 bool allowed_by_default); |
| 160 |
144 // Requests Geolocation Permission from the embedder. | 161 // Requests Geolocation Permission from the embedder. |
145 void RequestGeolocationPermission(int bridge_id, | 162 void RequestGeolocationPermission(int bridge_id, |
146 const GURL& requesting_frame, | 163 const GURL& requesting_frame, |
147 bool user_gesture, | 164 bool user_gesture, |
148 const base::Callback<void(bool)>& callback); | 165 const base::Callback<void(bool)>& callback); |
149 | 166 |
150 void OnWebViewGeolocationPermissionResponse( | 167 void OnWebViewGeolocationPermissionResponse( |
151 int bridge_id, | 168 int bridge_id, |
152 bool user_gesture, | 169 bool user_gesture, |
153 const base::Callback<void(bool)>& callback, | 170 const base::Callback<void(bool)>& callback, |
(...skipping 11 matching lines...) Expand all Loading... |
165 void OnWebViewDownloadPermissionResponse( | 182 void OnWebViewDownloadPermissionResponse( |
166 const base::Callback<void(bool)>& callback, | 183 const base::Callback<void(bool)>& callback, |
167 bool allow, | 184 bool allow, |
168 const std::string& user_input); | 185 const std::string& user_input); |
169 | 186 |
170 void OnWebViewPointerLockPermissionResponse( | 187 void OnWebViewPointerLockPermissionResponse( |
171 const base::Callback<void(bool)>& callback, | 188 const base::Callback<void(bool)>& callback, |
172 bool allow, | 189 bool allow, |
173 const std::string& user_input); | 190 const std::string& user_input); |
174 | 191 |
| 192 void OnWebViewNewWindowResponse(int new_window_instance_id, |
| 193 bool allow, |
| 194 const std::string& user_input); |
| 195 |
175 enum PermissionResponseAction { | 196 enum PermissionResponseAction { |
176 DENY, | 197 DENY, |
177 ALLOW, | 198 ALLOW, |
178 DEFAULT | 199 DEFAULT |
179 }; | 200 }; |
180 | 201 |
181 enum SetPermissionResult { | 202 enum SetPermissionResult { |
182 SET_PERMISSION_INVALID, | 203 SET_PERMISSION_INVALID, |
183 SET_PERMISSION_ALLOWED, | 204 SET_PERMISSION_ALLOWED, |
184 SET_PERMISSION_DENIED | 205 SET_PERMISSION_DENIED |
(...skipping 27 matching lines...) Expand all Loading... |
212 extensions::ScriptExecutor* script_executor() { | 233 extensions::ScriptExecutor* script_executor() { |
213 return script_executor_.get(); | 234 return script_executor_.get(); |
214 } | 235 } |
215 | 236 |
216 private: | 237 private: |
217 virtual ~WebViewGuest(); | 238 virtual ~WebViewGuest(); |
218 | 239 |
219 // A map to store the callback for a request keyed by the request's id. | 240 // A map to store the callback for a request keyed by the request's id. |
220 struct PermissionResponseInfo { | 241 struct PermissionResponseInfo { |
221 PermissionResponseCallback callback; | 242 PermissionResponseCallback callback; |
222 BrowserPluginPermissionType permission_type; | 243 WebViewPermissionType permission_type; |
223 bool allowed_by_default; | 244 bool allowed_by_default; |
224 PermissionResponseInfo(); | 245 PermissionResponseInfo(); |
225 PermissionResponseInfo(const PermissionResponseCallback& callback, | 246 PermissionResponseInfo(const PermissionResponseCallback& callback, |
226 BrowserPluginPermissionType permission_type, | 247 WebViewPermissionType permission_type, |
227 bool allowed_by_default); | 248 bool allowed_by_default); |
228 ~PermissionResponseInfo(); | 249 ~PermissionResponseInfo(); |
229 }; | 250 }; |
230 | 251 |
231 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, | 252 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, |
232 bool allow); | 253 bool allow); |
233 | 254 |
234 // Returns the top level items (ignoring submenus) as Value. | 255 // Returns the top level items (ignoring submenus) as Value. |
235 static scoped_ptr<base::ListValue> MenuModelToValue( | 256 static scoped_ptr<base::ListValue> MenuModelToValue( |
236 const ui::SimpleMenuModel& menu_model); | 257 const ui::SimpleMenuModel& menu_model); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 const chromeos::AccessibilityStatusEventDetails& details); | 306 const chromeos::AccessibilityStatusEventDetails& details); |
286 #endif | 307 #endif |
287 | 308 |
288 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); | 309 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); |
289 | 310 |
290 // Bridge IDs correspond to a geolocation request. This method will remove | 311 // Bridge IDs correspond to a geolocation request. This method will remove |
291 // the bookkeeping for a particular geolocation request associated with the | 312 // the bookkeeping for a particular geolocation request associated with the |
292 // provided |bridge_id|. It returns the request ID of the geolocation request. | 313 // provided |bridge_id|. It returns the request ID of the geolocation request. |
293 int RemoveBridgeID(int bridge_id); | 314 int RemoveBridgeID(int bridge_id); |
294 | 315 |
295 int RequestPermissionInternal( | 316 void LoadURLWithParams(const GURL& url, |
296 BrowserPluginPermissionType permission_type, | 317 const content::Referrer& referrer, |
297 const base::DictionaryValue& request_info, | 318 content::PageTransition transition_type, |
298 const PermissionResponseCallback& callback, | 319 content::WebContents* web_contents); |
299 bool allowed_by_default); | 320 |
| 321 void RequestNewWindowPermission( |
| 322 WindowOpenDisposition disposition, |
| 323 const gfx::Rect& initial_bounds, |
| 324 bool user_gesture, |
| 325 content::WebContents* new_contents); |
| 326 |
| 327 // Destroy unattached new windows that have been opened by this |
| 328 // WebViewGuest. |
| 329 void DestroyUnattachedWindows(); |
| 330 |
| 331 // Requests resolution of a potentially relative URL. |
| 332 GURL ResolveURL(const std::string& src); |
| 333 |
| 334 // Notification that a load in the guest resulted in abort. Note that |url| |
| 335 // may be invalid. |
| 336 void LoadAbort(bool is_top_level, |
| 337 const GURL& url, |
| 338 const std::string& error_type); |
| 339 |
| 340 |
| 341 // Creates a new guest window owned by this WebViewGuest. |
| 342 WebViewGuest* CreateNewGuestWindow(const content::OpenURLParams& params); |
300 | 343 |
301 ObserverList<extensions::TabHelper::ScriptExecutionObserver> | 344 ObserverList<extensions::TabHelper::ScriptExecutionObserver> |
302 script_observers_; | 345 script_observers_; |
303 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 346 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
304 | 347 |
305 content::NotificationRegistrar notification_registrar_; | 348 content::NotificationRegistrar notification_registrar_; |
306 | 349 |
307 // A counter to generate a unique request id for a context menu request. | 350 // A counter to generate a unique request id for a context menu request. |
308 // We only need the ids to be unique for a given WebViewGuest. | 351 // We only need the ids to be unique for a given WebViewGuest. |
309 int pending_context_menu_request_id_; | 352 int pending_context_menu_request_id_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 scoped_ptr<RenderViewContextMenu> pending_menu_; | 388 scoped_ptr<RenderViewContextMenu> pending_menu_; |
346 | 389 |
347 #if defined(OS_CHROMEOS) | 390 #if defined(OS_CHROMEOS) |
348 // Subscription to receive notifications on changes to a11y settings. | 391 // Subscription to receive notifications on changes to a11y settings. |
349 scoped_ptr<chromeos::AccessibilityStatusSubscription> | 392 scoped_ptr<chromeos::AccessibilityStatusSubscription> |
350 accessibility_subscription_; | 393 accessibility_subscription_; |
351 #endif | 394 #endif |
352 | 395 |
353 std::map<int, int> bridge_id_to_request_id_map_; | 396 std::map<int, int> bridge_id_to_request_id_map_; |
354 | 397 |
| 398 // Tracks the name, and target URL of the new window. Once the first |
| 399 // navigation commits, we no longer track this information. |
| 400 struct NewWindowInfo { |
| 401 GURL url; |
| 402 std::string name; |
| 403 NewWindowInfo(const GURL& url, const std::string& name) : |
| 404 url(url), |
| 405 name(name) {} |
| 406 }; |
| 407 |
| 408 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |
| 409 PendingWindowMap pending_new_windows_; |
| 410 |
355 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 411 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
356 }; | 412 }; |
357 | 413 |
358 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 414 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
OLD | NEW |