OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/web_request/chrome_extra_request_params.
h" |
| 6 |
| 7 #include "chrome/browser/extensions/extension_renderer_state.h" |
| 8 #include "content/public/browser/resource_request_info.h" |
| 9 #include "net/url_request/url_request.h" |
| 10 |
| 11 ChromeExtraRequestParams::ChromeExtraRequestParams() |
| 12 : tab_id_(-1), window_id_(-1) { |
| 13 } |
| 14 |
| 15 ChromeExtraRequestParams::ChromeExtraRequestParams( |
| 16 const ChromeExtraRequestParams& params) |
| 17 : tab_id_(params.tab_id()), window_id_(params.window_id()) { |
| 18 } |
| 19 |
| 20 ChromeExtraRequestParams::~ChromeExtraRequestParams() { |
| 21 } |
| 22 |
| 23 bool ChromeExtraRequestParams::OnInitFromValueCheck( |
| 24 const base::DictionaryValue& value) { |
| 25 for (base::DictionaryValue::Iterator it(value); !it.IsAtEnd(); it.Advance()) { |
| 26 if (it.key() == "tabId") { |
| 27 if (!it.value().GetAsInteger(&tab_id_)) |
| 28 return false; |
| 29 } else if (it.key() == "windowId") { |
| 30 if (!it.value().GetAsInteger(&window_id_)) |
| 31 return false; |
| 32 } else { |
| 33 return false; |
| 34 } |
| 35 } |
| 36 return true; |
| 37 } |
| 38 |
| 39 bool ChromeExtraRequestParams::OnGetMatchingListenersImplCheck( |
| 40 net:: URLRequest* request) const { |
| 41 if (!request->GetUserData(NULL)) |
| 42 return false; |
| 43 |
| 44 int tab_id = -1; |
| 45 int window_id = -1; |
| 46 const content::ResourceRequestInfo* info = |
| 47 content::ResourceRequestInfo::ForRequest(request); |
| 48 ExtensionRendererState::GetInstance()->GetTabAndWindowId( |
| 49 info, &tab_id, &window_id); |
| 50 return (tab_id_ != -1 && tab_id_ != tab_id) || |
| 51 (window_id_ != -1 && window_id_ != window_id) ? true : false; |
| 52 } |
OLD | NEW |