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" |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 removal_mask, | 637 removal_mask, |
| 636 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 638 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 637 GURL(), | 639 GURL(), |
| 638 content::StoragePartition::OriginMatcherFunction(), | 640 content::StoragePartition::OriginMatcherFunction(), |
| 639 remove_since, | 641 remove_since, |
| 640 base::Time::Now(), | 642 base::Time::Now(), |
| 641 callback); | 643 callback); |
| 642 return true; | 644 return true; |
| 643 } | 645 } |
| 644 | 646 |
| 647 void WebViewGuest::AddContentScripts(const std::string& script_name, | |
|
Fady Samuel
2015/03/11 11:43:17
This name is wrong. It adds a single script. Reall
| |
| 648 const UserScript& script) { | |
| 649 if (!master_) { | |
| 650 CHECK(host_id_); | |
| 651 master_ = ExtensionSystem::Get(browser_context()) | |
| 652 ->declarative_user_script_manager() | |
| 653 ->GetDeclarativeUserScriptMasterByID(*host_id_); | |
| 654 } | |
| 655 // If a script with the same script name exists, we delete the old one and | |
| 656 // then add the new one. | |
| 657 UserScriptMap::iterator iter = user_script_map_.find(script_name); | |
| 658 if (iter != user_script_map_.end()) { | |
| 659 master_->RemoveScript(iter->second); | |
| 660 user_script_map_.erase(iter); | |
| 661 } | |
| 662 | |
| 663 user_script_map_.insert( | |
| 664 std::pair<std::string, UserScript>(script_name, script)); | |
| 665 master_->AddScript(script); | |
| 666 } | |
| 667 | |
| 668 void WebViewGuest::RemoveContentScripts(const std::string& script_name) { | |
|
Fady Samuel
2015/03/11 11:43:17
This name is wrong. It removes a single script. Re
| |
| 669 auto iter = user_script_map_.find(script_name); | |
| 670 if (iter == user_script_map_.end() || !master_) | |
| 671 return; | |
| 672 master_->RemoveScript(iter->second); | |
| 673 user_script_map_.erase(iter); | |
| 674 } | |
| 675 | |
| 676 void WebViewGuest::RemoveAllContentScripts() { | |
| 677 if (!master_) | |
| 678 return; | |
| 679 auto iter = user_script_map_.begin(); | |
| 680 while (iter != user_script_map_.end()) { | |
| 681 master_->RemoveScript(iter->second); | |
| 682 iter = user_script_map_.erase(iter); | |
| 683 } | |
| 684 } | |
| 685 | |
| 645 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) | 686 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) |
| 646 : GuestView<WebViewGuest>(owner_web_contents), | 687 : GuestView<WebViewGuest>(owner_web_contents), |
| 647 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), | 688 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), |
| 648 find_helper_(this), | 689 find_helper_(this), |
| 649 is_overriding_user_agent_(false), | 690 is_overriding_user_agent_(false), |
| 650 guest_opaque_(true), | 691 guest_opaque_(true), |
| 651 javascript_dialog_helper_(this), | 692 javascript_dialog_helper_(this), |
| 652 current_zoom_factor_(1.0), | 693 current_zoom_factor_(1.0), |
| 653 allow_scaling_(false), | 694 allow_scaling_(false), |
| 695 host_id_(nullptr), | |
| 696 master_(nullptr), | |
| 654 weak_ptr_factory_(this) { | 697 weak_ptr_factory_(this) { |
| 655 web_view_guest_delegate_.reset( | 698 web_view_guest_delegate_.reset( |
| 656 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); | 699 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); |
| 657 } | 700 } |
| 658 | 701 |
| 659 WebViewGuest::~WebViewGuest() { | 702 WebViewGuest::~WebViewGuest() { |
| 660 } | 703 } |
| 661 | 704 |
| 662 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 705 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 663 content::RenderFrameHost* render_frame_host, | 706 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(), | 1312 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 1270 new_window_instance_id); | 1313 new_window_instance_id); |
| 1271 if (!guest) | 1314 if (!guest) |
| 1272 return; | 1315 return; |
| 1273 | 1316 |
| 1274 if (!allow) | 1317 if (!allow) |
| 1275 guest->Destroy(); | 1318 guest->Destroy(); |
| 1276 } | 1319 } |
| 1277 | 1320 |
| 1278 } // namespace extensions | 1321 } // namespace extensions |
| OLD | NEW |