Chromium Code Reviews| 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 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
| 28 #include "content/public/common/media_stream_request.h" | 28 #include "content/public/common/media_stream_request.h" |
| 29 #include "content/public/common/page_zoom.h" | 29 #include "content/public/common/page_zoom.h" |
| 30 #include "content/public/common/result_codes.h" | 30 #include "content/public/common/result_codes.h" |
| 31 #include "content/public/common/stop_find_action.h" | 31 #include "content/public/common/stop_find_action.h" |
| 32 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
| 33 #include "extensions/browser/api/declarative/rules_registry_service.h" | 33 #include "extensions/browser/api/declarative/rules_registry_service.h" |
| 34 #include "extensions/browser/api/extensions_api_client.h" | 34 #include "extensions/browser/api/extensions_api_client.h" |
| 35 #include "extensions/browser/api/web_request/web_request_api.h" | 35 #include "extensions/browser/api/web_request/web_request_api.h" |
| 36 #include "extensions/browser/api/web_view/web_view_internal_api.h" | 36 #include "extensions/browser/api/web_view/web_view_internal_api.h" |
| 37 #include "extensions/browser/declarative_user_script_manager.h" | |
| 38 #include "extensions/browser/declarative_user_script_master.h" | |
| 37 #include "extensions/browser/extension_system.h" | 39 #include "extensions/browser/extension_system.h" |
| 38 #include "extensions/browser/guest_view/guest_view_manager.h" | 40 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 39 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 41 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
| 40 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 42 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 41 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | 43 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" |
| 42 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 44 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 43 #include "extensions/common/constants.h" | 45 #include "extensions/common/constants.h" |
| 44 #include "extensions/common/extension_messages.h" | 46 #include "extensions/common/extension_messages.h" |
| 45 #include "extensions/common/guest_view/guest_view_constants.h" | 47 #include "extensions/common/guest_view/guest_view_constants.h" |
| 46 #include "extensions/strings/grit/extensions_strings.h" | 48 #include "extensions/strings/grit/extensions_strings.h" |
| 47 #include "ipc/ipc_message_macros.h" | 49 #include "ipc/ipc_message_macros.h" |
| 48 #include "net/base/escape.h" | 50 #include "net/base/escape.h" |
| 49 #include "net/base/net_errors.h" | 51 #include "net/base/net_errors.h" |
| 50 #include "ui/base/models/simple_menu_model.h" | 52 #include "ui/base/models/simple_menu_model.h" |
| 51 #include "url/url_constants.h" | 53 #include "url/url_constants.h" |
| 52 | 54 |
| 53 using base::UserMetricsAction; | 55 using base::UserMetricsAction; |
| 54 using content::RenderFrameHost; | 56 using content::RenderFrameHost; |
| 55 using content::ResourceType; | 57 using content::ResourceType; |
| 56 using content::WebContents; | 58 using content::WebContents; |
| 57 | 59 |
| 58 namespace extensions { | 60 namespace extensions { |
| 59 | 61 |
| 60 namespace { | 62 namespace { |
| 61 | 63 |
| 64 | |
|
Fady Samuel
2015/03/04 02:02:10
Remove this extra line.
Xi Han
2015/03/06 17:29:07
Done.
| |
| 62 std::string WindowOpenDispositionToString( | 65 std::string WindowOpenDispositionToString( |
| 63 WindowOpenDisposition window_open_disposition) { | 66 WindowOpenDisposition window_open_disposition) { |
| 64 switch (window_open_disposition) { | 67 switch (window_open_disposition) { |
| 65 case IGNORE_ACTION: | 68 case IGNORE_ACTION: |
| 66 return "ignore"; | 69 return "ignore"; |
| 67 case SAVE_TO_DISK: | 70 case SAVE_TO_DISK: |
| 68 return "save_to_disk"; | 71 return "save_to_disk"; |
| 69 case CURRENT_TAB: | 72 case CURRENT_TAB: |
| 70 return "current_tab"; | 73 return "current_tab"; |
| 71 case NEW_BACKGROUND_TAB: | 74 case NEW_BACKGROUND_TAB: |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 removal_mask, | 638 removal_mask, |
| 636 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 639 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 637 GURL(), | 640 GURL(), |
| 638 content::StoragePartition::OriginMatcherFunction(), | 641 content::StoragePartition::OriginMatcherFunction(), |
| 639 remove_since, | 642 remove_since, |
| 640 base::Time::Now(), | 643 base::Time::Now(), |
| 641 callback); | 644 callback); |
| 642 return true; | 645 return true; |
| 643 } | 646 } |
| 644 | 647 |
| 648 bool WebViewGuest::IsHostIDEmpty() { | |
|
Fady Samuel
2015/03/04 02:02:10
What does this mean?
Xi Han
2015/03/06 17:29:07
This function returns whether the host_id_ is null
| |
| 649 return !host_id_; | |
| 650 } | |
| 651 | |
| 652 void WebViewGuest::AddContentScripts(const std::string& script_name, | |
| 653 const UserScript& script) { | |
| 654 if (!master_) { | |
| 655 CHECK(host_id_); | |
| 656 master_ = ExtensionSystem::Get(browser_context()) | |
| 657 ->declarative_user_script_manager() | |
| 658 ->GetDeclarativeUserScriptMasterByID(*host_id_); | |
| 659 } | |
| 660 // If a script with the same script name exists, we delete the old one and | |
| 661 // then add the new one. | |
| 662 UserScriptMap::iterator iter = user_script_map_.find(script_name); | |
| 663 if (iter != user_script_map_.end()) { | |
| 664 master_->RemoveScript(iter->second); | |
| 665 user_script_map_.erase(iter); | |
| 666 } | |
| 667 | |
| 668 user_script_map_.insert( | |
| 669 std::pair<std::string, UserScript>(script_name, script)); | |
| 670 master_->AddScript(script); | |
|
Fady Samuel
2015/03/04 02:02:10
Does this plumbing work now?
Xi Han
2015/03/06 17:29:07
For webUI, since webUI needs a different way to lo
| |
| 671 } | |
| 672 | |
| 673 void WebViewGuest::RemoveContentScripts(const std::string& script_name) { | |
| 674 auto iter = user_script_map_.find(script_name); | |
| 675 if (iter == user_script_map_.end() || !master_) | |
| 676 return; | |
| 677 master_->RemoveScript(iter->second); | |
| 678 user_script_map_.erase(iter); | |
| 679 } | |
| 680 | |
| 681 void WebViewGuest::RemoveAllContentScripts() { | |
| 682 if (!master_) | |
| 683 return; | |
| 684 auto iter = user_script_map_.begin(); | |
| 685 while(iter != user_script_map_.end()) { | |
| 686 master_->RemoveScript(iter->second); | |
| 687 iter = user_script_map_.erase(iter); | |
| 688 } | |
| 689 } | |
| 690 | |
| 645 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) | 691 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) |
| 646 : GuestView<WebViewGuest>(owner_web_contents), | 692 : GuestView<WebViewGuest>(owner_web_contents), |
| 647 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), | 693 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), |
| 648 find_helper_(this), | 694 find_helper_(this), |
| 649 is_overriding_user_agent_(false), | 695 is_overriding_user_agent_(false), |
| 650 guest_opaque_(true), | 696 guest_opaque_(true), |
| 651 javascript_dialog_helper_(this), | 697 javascript_dialog_helper_(this), |
| 652 current_zoom_factor_(1.0), | 698 current_zoom_factor_(1.0), |
| 653 allow_scaling_(false), | 699 allow_scaling_(false), |
| 700 host_id_(nullptr), | |
| 701 master_(nullptr), | |
| 654 weak_ptr_factory_(this) { | 702 weak_ptr_factory_(this) { |
| 655 web_view_guest_delegate_.reset( | 703 web_view_guest_delegate_.reset( |
| 656 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); | 704 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); |
| 657 } | 705 } |
| 658 | 706 |
| 659 WebViewGuest::~WebViewGuest() { | 707 WebViewGuest::~WebViewGuest() { |
| 660 } | 708 } |
| 661 | 709 |
| 662 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 710 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 663 content::RenderFrameHost* render_frame_host, | 711 content::RenderFrameHost* render_frame_host, |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1317 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 1270 new_window_instance_id); | 1318 new_window_instance_id); |
| 1271 if (!guest) | 1319 if (!guest) |
| 1272 return; | 1320 return; |
| 1273 | 1321 |
| 1274 if (!allow) | 1322 if (!allow) |
| 1275 guest->Destroy(); | 1323 guest->Destroy(); |
| 1276 } | 1324 } |
| 1277 | 1325 |
| 1278 } // namespace extensions | 1326 } // namespace extensions |
| OLD | NEW |