Index: chrome/browser/extensions/api/web_request/chrome_extra_request_params.cc |
diff --git a/chrome/browser/extensions/api/web_request/chrome_extra_request_params.cc b/chrome/browser/extensions/api/web_request/chrome_extra_request_params.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..302a840df92a9f34176d062b1deda61d2dbc0309 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/web_request/chrome_extra_request_params.cc |
@@ -0,0 +1,52 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/extensions/api/web_request/chrome_extra_request_params.h" |
+ |
+#include "chrome/browser/extensions/extension_renderer_state.h" |
+#include "content/public/browser/resource_request_info.h" |
+#include "net/url_request/url_request.h" |
+ |
+ChromeExtraRequestParams::ChromeExtraRequestParams() |
+ : tab_id_(-1), window_id_(-1) { |
+} |
+ |
+ChromeExtraRequestParams::ChromeExtraRequestParams( |
+ const ChromeExtraRequestParams& params) |
+ : tab_id_(params.tab_id()), window_id_(params.window_id()) { |
+} |
+ |
+ChromeExtraRequestParams::~ChromeExtraRequestParams() { |
+} |
+ |
+bool ChromeExtraRequestParams::OnInitFromValueCheck( |
+ const base::DictionaryValue& value) { |
+ for (base::DictionaryValue::Iterator it(value); !it.IsAtEnd(); it.Advance()) { |
+ if (it.key() == "tabId") { |
+ if (!it.value().GetAsInteger(&tab_id_)) |
+ return false; |
+ } else if (it.key() == "windowId") { |
+ if (!it.value().GetAsInteger(&window_id_)) |
+ return false; |
+ } else { |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
+bool ChromeExtraRequestParams::OnGetMatchingListenersImplCheck( |
+ net:: URLRequest* request) const { |
+ if (!request->GetUserData(NULL)) |
+ return false; |
+ |
+ int tab_id = -1; |
+ int window_id = -1; |
+ const content::ResourceRequestInfo* info = |
+ content::ResourceRequestInfo::ForRequest(request); |
+ ExtensionRendererState::GetInstance()->GetTabAndWindowId( |
+ info, &tab_id, &window_id); |
+ return (tab_id_ != -1 && tab_id_ != tab_id) || |
+ (window_id_ != -1 && window_id_ != window_id) ? true : false; |
+} |