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

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

Issue 1056133005: Make WebUI webview content script work with incognito. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webview-content-script-api-from-xi
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | extensions/browser/declarative_user_script_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.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/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
11 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/stop_find_action.h" 14 #include "content/public/common/stop_find_action.h"
14 #include "content/public/common/url_fetcher.h" 15 #include "content/public/common/url_fetcher.h"
15 #include "extensions/browser/guest_view/web_view/web_view_constants.h" 16 #include "extensions/browser/guest_view/web_view/web_view_constants.h"
16 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager .h" 17 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager .h"
17 #include "extensions/common/api/web_view_internal.h" 18 #include "extensions/common/api/web_view_internal.h"
18 #include "extensions/common/error_utils.h" 19 #include "extensions/common/error_utils.h"
19 #include "extensions/common/manifest_constants.h" 20 #include "extensions/common/manifest_constants.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 for (const std::string& glob : exclude_globs) 185 for (const std::string& glob : exclude_globs)
185 script->add_exclude_glob(glob); 186 script->add_exclude_glob(glob);
186 } 187 }
187 188
188 return true; 189 return true;
189 } 190 }
190 191
191 bool Parse(std::vector<linked_ptr<ContentScriptDetails>> content_script_list, 192 bool Parse(std::vector<linked_ptr<ContentScriptDetails>> content_script_list,
192 const extensions::Extension* extension, 193 const extensions::Extension* extension,
193 const GURL& owner_base_url, 194 const GURL& owner_base_url,
195 bool is_incognito_enabled,
194 std::map<std::string, UserScript>* result, 196 std::map<std::string, UserScript>* result,
195 std::string* error) { 197 std::string* error) {
196 if (content_script_list.size() == 0) 198 if (content_script_list.size() == 0)
197 return false; 199 return false;
198 for (size_t i = 0; i < content_script_list.size(); ++i) { 200 for (size_t i = 0; i < content_script_list.size(); ++i) {
199 const ContentScriptDetails& script_value = *content_script_list[i]; 201 const ContentScriptDetails& script_value = *content_script_list[i];
200 const std::string& name = script_value.name; 202 const std::string& name = script_value.name;
201 UserScript script; 203 UserScript script;
202 if (!Parse(script_value, extension, owner_base_url, &script, error)) 204 if (!Parse(script_value, extension, owner_base_url, &script, error))
203 return false; 205 return false;
204 else 206 else {
207 script.set_incognito_enabled(is_incognito_enabled);
205 result->insert(std::pair<std::string, UserScript>(name, script)); 208 result->insert(std::pair<std::string, UserScript>(name, script));
209 }
206 } 210 }
207 return true; 211 return true;
208 } 212 }
209 213
210 // Initialize the user script. 214 // Initialize the user script.
211 void InitUserScript(UserScript* script, std::string name, HostID host_id) { 215 void InitUserScript(UserScript* script, std::string name, HostID host_id) {
212 if (!script) 216 if (!script)
213 return; 217 return;
214 script->set_id(UserScript::GenerateUserScriptID()); 218 script->set_id(UserScript::GenerateUserScriptID());
215 script->set_name(name); 219 script->set_name(name);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 scoped_ptr<web_view_internal::AddContentScripts::Params> params( 388 scoped_ptr<web_view_internal::AddContentScripts::Params> params(
385 web_view_internal::AddContentScripts::Params::Create(*args_)); 389 web_view_internal::AddContentScripts::Params::Create(*args_));
386 EXTENSION_FUNCTION_VALIDATE(params.get()); 390 EXTENSION_FUNCTION_VALIDATE(params.get());
387 391
388 int view_instance_id = 0; 392 int view_instance_id = 0;
389 if (!args_->GetInteger(0, &view_instance_id) || !view_instance_id) { 393 if (!args_->GetInteger(0, &view_instance_id) || !view_instance_id) {
390 SendResponse(false); 394 SendResponse(false);
391 return false; 395 return false;
392 } 396 }
393 397
398 const bool is_incognito_enabled = browser_context()->IsOffTheRecord();
399
394 GURL owner_base_url( 400 GURL owner_base_url(
395 render_view_host()->GetSiteInstance()->GetSiteURL().GetWithEmptyPath()); 401 render_view_host()->GetSiteInstance()->GetSiteURL().GetWithEmptyPath());
396 std::map<std::string, UserScript> result; 402 std::map<std::string, UserScript> result;
397 if (!Parse(params->content_script_list, extension(), owner_base_url, &result, 403 if (!Parse(params->content_script_list, extension(), owner_base_url,
398 &error_)) { 404 is_incognito_enabled, &result, &error_)) {
399 SendResponse(false); 405 SendResponse(false);
400 return false; 406 return false;
401 } 407 }
402 408
403 WebViewContentScriptManager* manager = 409 WebViewContentScriptManager* manager =
404 WebViewContentScriptManager::Get(browser_context()); 410 WebViewContentScriptManager::Get(browser_context());
405 if (!manager) { 411 if (!manager) {
406 SendResponse(false); 412 SendResponse(false);
407 return false; 413 return false;
408 } 414 }
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 // Will finish asynchronously. 884 // Will finish asynchronously.
879 return true; 885 return true;
880 } 886 }
881 887
882 void WebViewInternalClearDataFunction::ClearDataDone() { 888 void WebViewInternalClearDataFunction::ClearDataDone() {
883 Release(); // Balanced in RunAsync(). 889 Release(); // Balanced in RunAsync().
884 SendResponse(true); 890 SendResponse(true);
885 } 891 }
886 892
887 } // namespace extensions 893 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/declarative_user_script_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698