| OLD | NEW |
| 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 "chrome/browser/extensions/api/web_request/web_request_api.h" | 5 #include "chrome/browser/extensions/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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/browser/extensions/extension_prefs.h" | 29 #include "chrome/browser/extensions/extension_prefs.h" |
| 30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 31 #include "chrome/browser/extensions/extension_tab_id_map.h" | 31 #include "chrome/browser/extensions/extension_tab_id_map.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
| 34 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 34 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
| 35 #include "chrome/common/extensions/api/web_request.h" | 35 #include "chrome/common/extensions/api/web_request.h" |
| 36 #include "chrome/common/extensions/event_filtering_info.h" | 36 #include "chrome/common/extensions/event_filtering_info.h" |
| 37 #include "chrome/common/extensions/extension.h" | 37 #include "chrome/common/extensions/extension.h" |
| 38 #include "chrome/common/extensions/extension_constants.h" | 38 #include "chrome/common/extensions/extension_constants.h" |
| 39 #include "chrome/common/extensions/extension_error_utils.h" | |
| 40 #include "chrome/common/extensions/extension_messages.h" | 39 #include "chrome/common/extensions/extension_messages.h" |
| 41 #include "chrome/common/extensions/features/feature.h" | 40 #include "chrome/common/extensions/features/feature.h" |
| 42 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
| 43 #include "content/public/browser/browser_message_filter.h" | 42 #include "content/public/browser/browser_message_filter.h" |
| 44 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 45 #include "content/public/browser/render_process_host.h" | 44 #include "content/public/browser/render_process_host.h" |
| 46 #include "content/public/browser/resource_request_info.h" | 45 #include "content/public/browser/resource_request_info.h" |
| 46 #include "extensions/common/extension_error_utils.h" |
| 47 #include "extensions/common/url_pattern.h" | 47 #include "extensions/common/url_pattern.h" |
| 48 #include "googleurl/src/gurl.h" | 48 #include "googleurl/src/gurl.h" |
| 49 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
| 50 #include "net/base/auth.h" | 50 #include "net/base/auth.h" |
| 51 #include "net/base/net_errors.h" | 51 #include "net/base/net_errors.h" |
| 52 #include "net/base/upload_data.h" | 52 #include "net/base/upload_data.h" |
| 53 #include "net/base/upload_element.h" | 53 #include "net/base/upload_element.h" |
| 54 #include "net/http/http_response_headers.h" | 54 #include "net/http/http_response_headers.h" |
| 55 #include "net/url_request/url_request.h" | 55 #include "net/url_request/url_request.h" |
| 56 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" |
| 57 | 57 |
| 58 using base::DictionaryValue; | 58 using base::DictionaryValue; |
| 59 using base::ListValue; | 59 using base::ListValue; |
| 60 using base::StringValue; | 60 using base::StringValue; |
| 61 using chrome::VersionInfo; | 61 using chrome::VersionInfo; |
| 62 using content::BrowserMessageFilter; | 62 using content::BrowserMessageFilter; |
| 63 using content::BrowserThread; | 63 using content::BrowserThread; |
| 64 using content::ResourceRequestInfo; | 64 using content::ResourceRequestInfo; |
| 65 using extensions::ErrorUtils; |
| 65 using extensions::Extension; | 66 using extensions::Extension; |
| 66 using extensions::Feature; | 67 using extensions::Feature; |
| 67 | 68 |
| 68 using extensions::web_navigation_api_helpers::GetFrameId; | 69 using extensions::web_navigation_api_helpers::GetFrameId; |
| 69 | 70 |
| 70 namespace helpers = extension_web_request_api_helpers; | 71 namespace helpers = extension_web_request_api_helpers; |
| 71 namespace keys = extension_web_request_api_constants; | 72 namespace keys = extension_web_request_api_constants; |
| 72 namespace web_request = extensions::api::web_request; | 73 namespace web_request = extensions::api::web_request; |
| 73 | 74 |
| 74 namespace { | 75 namespace { |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 if (!value.GetList("urls", &urls_value)) | 406 if (!value.GetList("urls", &urls_value)) |
| 406 return false; | 407 return false; |
| 407 for (size_t i = 0; i < urls_value->GetSize(); ++i) { | 408 for (size_t i = 0; i < urls_value->GetSize(); ++i) { |
| 408 std::string url; | 409 std::string url; |
| 409 URLPattern pattern( | 410 URLPattern pattern( |
| 410 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | | 411 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | |
| 411 URLPattern::SCHEME_FTP | URLPattern::SCHEME_FILE | | 412 URLPattern::SCHEME_FTP | URLPattern::SCHEME_FILE | |
| 412 URLPattern::SCHEME_EXTENSION); | 413 URLPattern::SCHEME_EXTENSION); |
| 413 if (!urls_value->GetString(i, &url) || | 414 if (!urls_value->GetString(i, &url) || |
| 414 pattern.Parse(url) != URLPattern::PARSE_SUCCESS) { | 415 pattern.Parse(url) != URLPattern::PARSE_SUCCESS) { |
| 415 *error = ExtensionErrorUtils::FormatErrorMessage( | 416 *error = ErrorUtils::FormatErrorMessage( |
| 416 keys::kInvalidRequestFilterUrl, url); | 417 keys::kInvalidRequestFilterUrl, url); |
| 417 return false; | 418 return false; |
| 418 } | 419 } |
| 419 urls.AddPattern(pattern); | 420 urls.AddPattern(pattern); |
| 420 } | 421 } |
| 421 } else if (*key == "types") { | 422 } else if (*key == "types") { |
| 422 const ListValue* types_value = NULL; | 423 const ListValue* types_value = NULL; |
| 423 if (!value.GetList("types", &types_value)) | 424 if (!value.GetList("types", &types_value)) |
| 424 return false; | 425 return false; |
| 425 for (size_t i = 0; i < types_value->GetSize(); ++i) { | 426 for (size_t i = 0; i < types_value->GetSize(); ++i) { |
| (...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 EXTENSION_FUNCTION_VALIDATE(value->GetBoolean("cancel", &cancel)); | 1784 EXTENSION_FUNCTION_VALIDATE(value->GetBoolean("cancel", &cancel)); |
| 1784 response->cancel = cancel; | 1785 response->cancel = cancel; |
| 1785 } | 1786 } |
| 1786 | 1787 |
| 1787 if (value->HasKey("redirectUrl")) { | 1788 if (value->HasKey("redirectUrl")) { |
| 1788 std::string new_url_str; | 1789 std::string new_url_str; |
| 1789 EXTENSION_FUNCTION_VALIDATE(value->GetString("redirectUrl", | 1790 EXTENSION_FUNCTION_VALIDATE(value->GetString("redirectUrl", |
| 1790 &new_url_str)); | 1791 &new_url_str)); |
| 1791 response->new_url = GURL(new_url_str); | 1792 response->new_url = GURL(new_url_str); |
| 1792 if (!response->new_url.is_valid()) { | 1793 if (!response->new_url.is_valid()) { |
| 1793 error_ = ExtensionErrorUtils::FormatErrorMessage( | 1794 error_ = ErrorUtils::FormatErrorMessage( |
| 1794 keys::kInvalidRedirectUrl, new_url_str); | 1795 keys::kInvalidRedirectUrl, new_url_str); |
| 1795 return false; | 1796 return false; |
| 1796 } | 1797 } |
| 1797 } | 1798 } |
| 1798 | 1799 |
| 1799 if (value->HasKey("requestHeaders")) { | 1800 if (value->HasKey("requestHeaders")) { |
| 1800 ListValue* request_headers_value = NULL; | 1801 ListValue* request_headers_value = NULL; |
| 1801 response->request_headers.reset(new net::HttpRequestHeaders()); | 1802 response->request_headers.reset(new net::HttpRequestHeaders()); |
| 1802 EXTENSION_FUNCTION_VALIDATE(value->GetList(keys::kRequestHeadersKey, | 1803 EXTENSION_FUNCTION_VALIDATE(value->GetList(keys::kRequestHeadersKey, |
| 1803 &request_headers_value)); | 1804 &request_headers_value)); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1909 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1910 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 1910 adblock = true; | 1911 adblock = true; |
| 1911 } else { | 1912 } else { |
| 1912 other = true; | 1913 other = true; |
| 1913 } | 1914 } |
| 1914 } | 1915 } |
| 1915 } | 1916 } |
| 1916 | 1917 |
| 1917 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1918 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 1918 } | 1919 } |
| OLD | NEW |