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 EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 5 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 6 #define EXTENSIONS_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 "content/public/browser/javascript_dialog_manager.h" | 11 #include "content/public/browser/javascript_dialog_manager.h" |
12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
14 #include "extensions/browser/guest_view/guest_view.h" | 14 #include "extensions/browser/guest_view/guest_view.h" |
15 #include "extensions/browser/guest_view/web_view/javascript_dialog_helper.h" | 15 #include "extensions/browser/guest_view/web_view/javascript_dialog_helper.h" |
16 #include "extensions/browser/guest_view/web_view/web_view_find_helper.h" | 16 #include "extensions/browser/guest_view/web_view/web_view_find_helper.h" |
17 #include "extensions/browser/guest_view/web_view/web_view_guest_delegate.h" | 17 #include "extensions/browser/guest_view/web_view/web_view_guest_delegate.h" |
18 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 18 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
19 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | 19 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" |
20 #include "extensions/browser/script_executor.h" | 20 #include "extensions/browser/script_executor.h" |
21 | 21 |
22 namespace blink { | 22 namespace blink { |
23 struct WebFindOptions; | 23 struct WebFindOptions; |
24 } // nanespace blink | 24 } // nanespace blink |
25 | 25 |
26 namespace extensions { | 26 namespace extensions { |
27 | 27 |
| 28 class DeclarativeUserScriptMaster; |
28 class WebViewInternalFindFunction; | 29 class WebViewInternalFindFunction; |
29 | 30 |
30 // A WebViewGuest provides the browser-side implementation of the <webview> API | 31 // A WebViewGuest provides the browser-side implementation of the <webview> API |
31 // and manages the dispatch of <webview> extension events. WebViewGuest is | 32 // and manages the dispatch of <webview> extension events. WebViewGuest is |
32 // created on attachment. That is, when a guest WebContents is associated with | 33 // created on attachment. That is, when a guest WebContents is associated with |
33 // a particular embedder WebContents. This happens on either initial navigation | 34 // a particular embedder WebContents. This happens on either initial navigation |
34 // or through the use of the New Window API, when a new window is attached to | 35 // or through the use of the New Window API, when a new window is attached to |
35 // a particular <webview>. | 36 // a particular <webview>. |
36 class WebViewGuest : public GuestView<WebViewGuest>, | 37 class WebViewGuest : public GuestView<WebViewGuest>, |
37 public content::NotificationObserver { | 38 public content::NotificationObserver { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 void Terminate(); | 229 void Terminate(); |
229 | 230 |
230 // Clears data in the storage partition of this guest. | 231 // Clears data in the storage partition of this guest. |
231 // | 232 // |
232 // Partition data that are newer than |removal_since| will be removed. | 233 // Partition data that are newer than |removal_since| will be removed. |
233 // |removal_mask| corresponds to bitmask in StoragePartition::RemoveDataMask. | 234 // |removal_mask| corresponds to bitmask in StoragePartition::RemoveDataMask. |
234 bool ClearData(const base::Time remove_since, | 235 bool ClearData(const base::Time remove_since, |
235 uint32 removal_mask, | 236 uint32 removal_mask, |
236 const base::Closure& callback); | 237 const base::Closure& callback); |
237 | 238 |
| 239 // Adds content script to inject on the guest. |
| 240 void AddContentScripts(const std::string& script_name, |
| 241 const UserScript& script); |
| 242 |
| 243 // Removes content script by |script_name|. |
| 244 void RemoveContentScripts(const std::string& script_name); |
| 245 |
| 246 // Removes all content scripts added by the guest. |
| 247 void RemoveAllContentScripts(); |
| 248 |
| 249 // Returns whether |host_id_| is nullptr. |
| 250 bool IsHostIDEmpty(); |
| 251 |
238 ScriptExecutor* script_executor() { return script_executor_.get(); } | 252 ScriptExecutor* script_executor() { return script_executor_.get(); } |
| 253 const HostID& host_id() { return *host_id_; } |
| 254 void set_host_id(scoped_ptr<const HostID> host_id) { |
| 255 host_id_ = host_id.Pass(); |
| 256 } |
239 | 257 |
240 private: | 258 private: |
241 friend class WebViewPermissionHelper; | 259 friend class WebViewPermissionHelper; |
242 | 260 |
| 261 using UserScriptMap = std::map<std::string, UserScript>; |
| 262 |
243 explicit WebViewGuest(content::WebContents* owner_web_contents); | 263 explicit WebViewGuest(content::WebContents* owner_web_contents); |
244 | 264 |
245 ~WebViewGuest() override; | 265 ~WebViewGuest() override; |
246 | 266 |
247 void AttachWebViewHelpers(content::WebContents* contents); | 267 void AttachWebViewHelpers(content::WebContents* contents); |
248 | 268 |
249 void OnWebViewNewWindowResponse(int new_window_instance_id, | 269 void OnWebViewNewWindowResponse(int new_window_instance_id, |
250 bool allow, | 270 bool allow, |
251 const std::string& user_input); | 271 const std::string& user_input); |
252 | 272 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 385 |
366 using PendingWindowMap = std::map<WebViewGuest*, NewWindowInfo>; | 386 using PendingWindowMap = std::map<WebViewGuest*, NewWindowInfo>; |
367 PendingWindowMap pending_new_windows_; | 387 PendingWindowMap pending_new_windows_; |
368 | 388 |
369 // Stores the current zoom factor. | 389 // Stores the current zoom factor. |
370 double current_zoom_factor_; | 390 double current_zoom_factor_; |
371 | 391 |
372 // Determines if this guest accepts pinch-zoom gestures. | 392 // Determines if this guest accepts pinch-zoom gestures. |
373 bool allow_scaling_; | 393 bool allow_scaling_; |
374 | 394 |
| 395 // The ID of the injection host of the guest. |
| 396 scoped_ptr<const HostID> host_id_; |
| 397 |
| 398 DeclarativeUserScriptMaster* master_; |
| 399 |
| 400 UserScriptMap user_script_map_; |
| 401 |
375 // This is used to ensure pending tasks will not fire after this object is | 402 // This is used to ensure pending tasks will not fire after this object is |
376 // destroyed. | 403 // destroyed. |
377 base::WeakPtrFactory<WebViewGuest> weak_ptr_factory_; | 404 base::WeakPtrFactory<WebViewGuest> weak_ptr_factory_; |
378 | 405 |
379 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 406 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
380 }; | 407 }; |
381 | 408 |
382 } // namespace extensions | 409 } // namespace extensions |
383 | 410 |
384 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 411 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
OLD | NEW |