Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: extensions/browser/api/guest_view/web_view/web_view_internal_api.cc

Issue 2228743002: Rework some UserScriptLoader logic in preparation to removing UserScript copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/api/guest_view/web_view/web_view_internal_api.h" 5 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 return true; 209 return true;
210 } 210 }
211 211
212 bool ParseContentScripts( 212 bool ParseContentScripts(
213 const std::vector<ContentScriptDetails>& content_script_list, 213 const std::vector<ContentScriptDetails>& content_script_list,
214 const extensions::Extension* extension, 214 const extensions::Extension* extension,
215 const HostID& host_id, 215 const HostID& host_id,
216 bool incognito_enabled, 216 bool incognito_enabled,
217 const GURL& owner_base_url, 217 const GURL& owner_base_url,
218 std::set<UserScript>* result, 218 extensions::UserScriptList* result,
219 std::string* error) { 219 std::string* error) {
220 if (content_script_list.empty()) 220 if (content_script_list.empty())
221 return false; 221 return false;
222 222
223 std::set<std::string> names; 223 std::set<std::string> names;
224 for (const ContentScriptDetails& script_value : content_script_list) { 224 for (const ContentScriptDetails& script_value : content_script_list) {
225 const std::string& name = script_value.name; 225 const std::string& name = script_value.name;
226 if (!names.insert(name).second) { 226 if (!names.insert(name).second) {
227 // The name was already in the list. 227 // The name was already in the list.
228 *error = kDuplicatedContentScriptNamesError; 228 *error = kDuplicatedContentScriptNamesError;
229 return false; 229 return false;
230 } 230 }
231 231
232 UserScript script; 232 UserScript script;
233 if (!ParseContentScript(script_value, extension, owner_base_url, &script, 233 if (!ParseContentScript(script_value, extension, owner_base_url, &script,
234 error)) 234 error))
235 return false; 235 return false;
236 236
237 script.set_id(UserScript::GenerateUserScriptID()); 237 script.set_id(UserScript::GenerateUserScriptID());
238 script.set_name(name); 238 script.set_name(name);
239 script.set_incognito_enabled(incognito_enabled); 239 script.set_incognito_enabled(incognito_enabled);
240 script.set_host_id(host_id); 240 script.set_host_id(host_id);
241 script.set_consumer_instance_type(UserScript::WEBVIEW); 241 script.set_consumer_instance_type(UserScript::WEBVIEW);
242 result->insert(script); 242 result->push_back(script);
243 } 243 }
244 return true; 244 return true;
245 } 245 }
246 246
247 } // namespace 247 } // namespace
248 248
249 namespace extensions { 249 namespace extensions {
250 250
251 bool LegacyWebViewInternalExtensionFunction::RunAsync() { 251 bool LegacyWebViewInternalExtensionFunction::RunAsync() {
252 int instance_id = 0; 252 int instance_id = 0;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 WebViewInternalAddContentScriptsFunction::Run() { 493 WebViewInternalAddContentScriptsFunction::Run() {
494 std::unique_ptr<web_view_internal::AddContentScripts::Params> params( 494 std::unique_ptr<web_view_internal::AddContentScripts::Params> params(
495 web_view_internal::AddContentScripts::Params::Create(*args_)); 495 web_view_internal::AddContentScripts::Params::Create(*args_));
496 EXTENSION_FUNCTION_VALIDATE(params.get()); 496 EXTENSION_FUNCTION_VALIDATE(params.get());
497 497
498 if (!params->instance_id) 498 if (!params->instance_id)
499 return RespondNow(Error(kViewInstanceIdError)); 499 return RespondNow(Error(kViewInstanceIdError));
500 500
501 GURL owner_base_url( 501 GURL owner_base_url(
502 render_frame_host()->GetSiteInstance()->GetSiteURL().GetWithEmptyPath()); 502 render_frame_host()->GetSiteInstance()->GetSiteURL().GetWithEmptyPath());
503 std::set<UserScript> result;
504
505 content::WebContents* sender_web_contents = GetSenderWebContents(); 503 content::WebContents* sender_web_contents = GetSenderWebContents();
506 HostID host_id = GenerateHostIDFromEmbedder(extension(), sender_web_contents); 504 HostID host_id = GenerateHostIDFromEmbedder(extension(), sender_web_contents);
507 bool incognito_enabled = browser_context()->IsOffTheRecord(); 505 bool incognito_enabled = browser_context()->IsOffTheRecord();
508 506
507 UserScriptList result;
509 if (!ParseContentScripts(params->content_script_list, extension(), host_id, 508 if (!ParseContentScripts(params->content_script_list, extension(), host_id,
510 incognito_enabled, owner_base_url, &result, &error_)) 509 incognito_enabled, owner_base_url, &result, &error_))
511 return RespondNow(Error(error_)); 510 return RespondNow(Error(error_));
512 511
513 WebViewContentScriptManager* manager = 512 WebViewContentScriptManager* manager =
514 WebViewContentScriptManager::Get(browser_context()); 513 WebViewContentScriptManager::Get(browser_context());
515 DCHECK(manager); 514 DCHECK(manager);
516 515
517 manager->AddContentScripts( 516 manager->AddContentScripts(
518 sender_web_contents->GetRenderProcessHost()->GetID(), render_frame_host(), 517 sender_web_contents->GetRenderProcessHost()->GetID(), render_frame_host(),
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 // Will finish asynchronously. 964 // Will finish asynchronously.
966 return true; 965 return true;
967 } 966 }
968 967
969 void WebViewInternalClearDataFunction::ClearDataDone() { 968 void WebViewInternalClearDataFunction::ClearDataDone() {
970 Release(); // Balanced in RunAsync(). 969 Release(); // Balanced in RunAsync().
971 SendResponse(true); 970 SendResponse(true);
972 } 971 }
973 972
974 } // namespace extensions 973 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/shared_user_script_master.cc ('k') | extensions/browser/declarative_user_script_master.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698