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

Side by Side Diff: extensions/browser/api/web_request/web_request_api.cc

Issue 670173002: Fix webrequest api for webview in webui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scoped_refptr not testable Created 6 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/web_request/web_request_api.h" 5 #include "extensions/browser/api/web_request/web_request_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after
2206 2206
2207 int webview_instance_id = 0; 2207 int webview_instance_id = 0;
2208 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &webview_instance_id)); 2208 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &webview_instance_id));
2209 2209
2210 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender = 2210 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender =
2211 ipc_sender_weak(); 2211 ipc_sender_weak();
2212 int embedder_process_id = 2212 int embedder_process_id =
2213 ipc_sender.get() ? ipc_sender->render_process_id() : -1; 2213 ipc_sender.get() ? ipc_sender->render_process_id() : -1;
2214 2214
2215 const Extension* extension = 2215 const Extension* extension =
2216 extension_info_map()->extensions().GetByID(extension_id()); 2216 extension_info_map()->extensions().GetByID(extension_id_safe());
2217 std::string extension_name = extension ? extension->name() : extension_id(); 2217 std::string extension_name =
2218 extension ? extension->name() : extension_id_safe();
2218 2219
2219 bool is_web_view_guest = webview_instance_id != 0; 2220 bool is_web_view_guest = webview_instance_id != 0;
2220 // We check automatically whether the extension has the 'webRequest' 2221 // We check automatically whether the extension has the 'webRequest'
2221 // permission. For blocking calls we require the additional permission 2222 // permission. For blocking calls we require the additional permission
2222 // 'webRequestBlocking'. 2223 // 'webRequestBlocking'.
2223 if ((!is_web_view_guest && 2224 if ((!is_web_view_guest &&
2224 extra_info_spec & 2225 extra_info_spec &
2225 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING | 2226 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING |
2226 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) && 2227 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) &&
2227 !extension->permissions_data()->HasAPIPermission( 2228 !extension->permissions_data()->HasAPIPermission(
2228 extensions::APIPermission::kWebRequestBlocking)) { 2229 extensions::APIPermission::kWebRequestBlocking)) {
2229 error_ = keys::kBlockingPermissionRequired; 2230 error_ = keys::kBlockingPermissionRequired;
2230 return false; 2231 return false;
2231 } 2232 }
2232 2233
2233 // We allow to subscribe to patterns that are broader than the host 2234 // We allow to subscribe to patterns that are broader than the host
2234 // permissions. E.g., we could subscribe to http://www.example.com/* 2235 // permissions. E.g., we could subscribe to http://www.example.com/*
2235 // while having host permissions for http://www.example.com/foo/* and 2236 // while having host permissions for http://www.example.com/foo/* and
2236 // http://www.example.com/bar/*. 2237 // http://www.example.com/bar/*.
2237 // For this reason we do only a coarse check here to warn the extension 2238 // For this reason we do only a coarse check here to warn the extension
2238 // developer if he does something obviously wrong. 2239 // developer if he does something obviously wrong.
2239 if (!is_web_view_guest && 2240 if (!is_web_view_guest &&
2240 extension->permissions_data()->GetEffectiveHostPermissions().is_empty()) { 2241 extension->permissions_data()->GetEffectiveHostPermissions().is_empty()) {
2241 error_ = keys::kHostPermissionsRequired; 2242 error_ = keys::kHostPermissionsRequired;
2242 return false; 2243 return false;
2243 } 2244 }
2244 2245
2245 bool success = 2246 bool success =
2246 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( 2247 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener(
2247 profile_id(), extension_id(), extension_name, 2248 profile_id(), extension_id_safe(), extension_name,
2248 event_name, sub_event_name, filter, extra_info_spec, 2249 event_name, sub_event_name, filter, extra_info_spec,
2249 embedder_process_id, webview_instance_id, ipc_sender_weak()); 2250 embedder_process_id, webview_instance_id, ipc_sender_weak());
2250 EXTENSION_FUNCTION_VALIDATE(success); 2251 EXTENSION_FUNCTION_VALIDATE(success);
2251 2252
2252 helpers::ClearCacheOnNavigation(); 2253 helpers::ClearCacheOnNavigation();
2253 2254
2254 BrowserThread::PostTask(BrowserThread::UI, 2255 BrowserThread::PostTask(BrowserThread::UI,
2255 FROM_HERE, 2256 FROM_HERE,
2256 base::Bind(&helpers::NotifyWebRequestAPIUsed, 2257 base::Bind(&helpers::NotifyWebRequestAPIUsed,
2257 profile_id(), 2258 profile_id(),
2258 make_scoped_refptr(extension))); 2259 make_scoped_refptr(extension)));
2259 2260
2260 return true; 2261 return true;
2261 } 2262 }
2262 2263
2263 void WebRequestInternalEventHandledFunction::RespondWithError( 2264 void WebRequestInternalEventHandledFunction::RespondWithError(
2264 const std::string& event_name, 2265 const std::string& event_name,
2265 const std::string& sub_event_name, 2266 const std::string& sub_event_name,
2266 uint64 request_id, 2267 uint64 request_id,
2267 scoped_ptr<ExtensionWebRequestEventRouter::EventResponse> response, 2268 scoped_ptr<ExtensionWebRequestEventRouter::EventResponse> response,
2268 const std::string& error) { 2269 const std::string& error) {
2269 error_ = error; 2270 error_ = error;
2270 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( 2271 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled(
2271 profile_id(), 2272 profile_id(),
2272 extension_id(), 2273 extension_id_safe(),
2273 event_name, 2274 event_name,
2274 sub_event_name, 2275 sub_event_name,
2275 request_id, 2276 request_id,
2276 response.release()); 2277 response.release());
2277 } 2278 }
2278 2279
2279 bool WebRequestInternalEventHandledFunction::RunSync() { 2280 bool WebRequestInternalEventHandledFunction::RunSync() {
2280 std::string event_name; 2281 std::string event_name;
2281 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); 2282 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name));
2282 2283
2283 std::string sub_event_name; 2284 std::string sub_event_name;
2284 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &sub_event_name)); 2285 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &sub_event_name));
2285 2286
2286 std::string request_id_str; 2287 std::string request_id_str;
2287 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &request_id_str)); 2288 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &request_id_str));
2288 uint64 request_id; 2289 uint64 request_id;
2289 EXTENSION_FUNCTION_VALIDATE(base::StringToUint64(request_id_str, 2290 EXTENSION_FUNCTION_VALIDATE(base::StringToUint64(request_id_str,
2290 &request_id)); 2291 &request_id));
2291 2292
2292 scoped_ptr<ExtensionWebRequestEventRouter::EventResponse> response; 2293 scoped_ptr<ExtensionWebRequestEventRouter::EventResponse> response;
2293 if (HasOptionalArgument(3)) { 2294 if (HasOptionalArgument(3)) {
2294 base::DictionaryValue* value = NULL; 2295 base::DictionaryValue* value = NULL;
2295 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(3, &value)); 2296 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(3, &value));
2296 2297
2297 if (!value->empty()) { 2298 if (!value->empty()) {
2298 base::Time install_time = 2299 base::Time install_time =
2299 extension_info_map()->GetInstallTime(extension_id()); 2300 extension_info_map()->GetInstallTime(extension_id_safe());
2300 response.reset(new ExtensionWebRequestEventRouter::EventResponse( 2301 response.reset(new ExtensionWebRequestEventRouter::EventResponse(
2301 extension_id(), install_time)); 2302 extension_id_safe(), install_time));
2302 } 2303 }
2303 2304
2304 if (value->HasKey("cancel")) { 2305 if (value->HasKey("cancel")) {
2305 // Don't allow cancel mixed with other keys. 2306 // Don't allow cancel mixed with other keys.
2306 if (value->size() != 1) { 2307 if (value->size() != 1) {
2307 RespondWithError(event_name, 2308 RespondWithError(event_name,
2308 sub_event_name, 2309 sub_event_name,
2309 request_id, 2310 request_id,
2310 response.Pass(), 2311 response.Pass(),
2311 keys::kInvalidBlockingResponse); 2312 keys::kInvalidBlockingResponse);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 EXTENSION_FUNCTION_VALIDATE( 2415 EXTENSION_FUNCTION_VALIDATE(
2415 credentials_value->GetString(keys::kUsernameKey, &username)); 2416 credentials_value->GetString(keys::kUsernameKey, &username));
2416 EXTENSION_FUNCTION_VALIDATE( 2417 EXTENSION_FUNCTION_VALIDATE(
2417 credentials_value->GetString(keys::kPasswordKey, &password)); 2418 credentials_value->GetString(keys::kPasswordKey, &password));
2418 response->auth_credentials.reset( 2419 response->auth_credentials.reset(
2419 new net::AuthCredentials(username, password)); 2420 new net::AuthCredentials(username, password));
2420 } 2421 }
2421 } 2422 }
2422 2423
2423 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( 2424 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled(
2424 profile_id(), extension_id(), event_name, sub_event_name, request_id, 2425 profile_id(), extension_id_safe(), event_name, sub_event_name, request_id,
2425 response.release()); 2426 response.release());
2426 2427
2427 return true; 2428 return true;
2428 } 2429 }
2429 2430
2430 void WebRequestHandlerBehaviorChangedFunction::GetQuotaLimitHeuristics( 2431 void WebRequestHandlerBehaviorChangedFunction::GetQuotaLimitHeuristics(
2431 extensions::QuotaLimitHeuristics* heuristics) const { 2432 extensions::QuotaLimitHeuristics* heuristics) const {
2432 extensions::QuotaLimitHeuristic::Config config = { 2433 extensions::QuotaLimitHeuristic::Config config = {
2433 // See web_request.json for current value. 2434 // See web_request.json for current value.
2434 web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES, 2435 web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES,
2435 base::TimeDelta::FromMinutes(10)}; 2436 base::TimeDelta::FromMinutes(10)};
2436 extensions::QuotaLimitHeuristic::BucketMapper* bucket_mapper = 2437 extensions::QuotaLimitHeuristic::BucketMapper* bucket_mapper =
2437 new extensions::QuotaLimitHeuristic::SingletonBucketMapper(); 2438 new extensions::QuotaLimitHeuristic::SingletonBucketMapper();
2438 ClearCacheQuotaHeuristic* heuristic = 2439 ClearCacheQuotaHeuristic* heuristic =
2439 new ClearCacheQuotaHeuristic(config, bucket_mapper); 2440 new ClearCacheQuotaHeuristic(config, bucket_mapper);
2440 heuristics->push_back(heuristic); 2441 heuristics->push_back(heuristic);
2441 } 2442 }
2442 2443
2443 void WebRequestHandlerBehaviorChangedFunction::OnQuotaExceeded( 2444 void WebRequestHandlerBehaviorChangedFunction::OnQuotaExceeded(
2444 const std::string& violation_error) { 2445 const std::string& violation_error) {
2445 // Post warning message. 2446 // Post warning message.
2446 WarningSet warnings; 2447 WarningSet warnings;
2447 warnings.insert( 2448 warnings.insert(
2448 Warning::CreateRepeatedCacheFlushesWarning(extension_id())); 2449 Warning::CreateRepeatedCacheFlushesWarning(extension_id_safe()));
2449 BrowserThread::PostTask( 2450 BrowserThread::PostTask(
2450 BrowserThread::UI, 2451 BrowserThread::UI,
2451 FROM_HERE, 2452 FROM_HERE,
2452 base::Bind(&WarningService::NotifyWarningsOnUI, profile_id(), warnings)); 2453 base::Bind(&WarningService::NotifyWarningsOnUI, profile_id(), warnings));
2453 2454
2454 // Continue gracefully. 2455 // Continue gracefully.
2455 RunSync(); 2456 RunSync();
2456 } 2457 }
2457 2458
2458 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { 2459 bool WebRequestHandlerBehaviorChangedFunction::RunSync() {
2459 helpers::ClearCacheOnNavigation(); 2460 helpers::ClearCacheOnNavigation();
2460 return true; 2461 return true;
2461 } 2462 }
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/web_request_api.h ('k') | extensions/browser/api/web_request/web_request_api_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698