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

Side by Side Diff: chrome/browser/extensions/chrome_extension_function_details.cc

Issue 2296603005: [Extensions] Reuse ChromeExtensionFunctionDetails (Closed)
Patch Set: Created 4 years, 3 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 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 "chrome/browser/extensions/chrome_extension_function_details.h" 5 #include "chrome/browser/extensions/chrome_extension_function_details.h"
6 6
7 #include "chrome/browser/extensions/extension_tab_util.h" 7 #include "chrome/browser/extensions/extension_tab_util.h"
8 #include "chrome/browser/extensions/window_controller.h" 8 #include "chrome/browser/extensions/window_controller.h"
9 #include "chrome/browser/extensions/window_controller_list.h" 9 #include "chrome/browser/extensions/window_controller_list.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 } 50 }
51 51
52 // Otherwise, try to default to a reasonable browser. If |include_incognito_| 52 // Otherwise, try to default to a reasonable browser. If |include_incognito_|
53 // is true, we will also search browsers in the incognito version of this 53 // is true, we will also search browsers in the incognito version of this
54 // profile. Note that the profile may already be incognito, in which case 54 // profile. Note that the profile may already be incognito, in which case
55 // we will search the incognito version only, regardless of the value of 55 // we will search the incognito version only, regardless of the value of
56 // |include_incognito|. Look only for browsers on the active desktop as it is 56 // |include_incognito|. Look only for browsers on the active desktop as it is
57 // preferable to pretend no browser is open then to return a browser on 57 // preferable to pretend no browser is open then to return a browser on
58 // another desktop. 58 // another desktop.
59 if (function_->render_frame_host()) { 59 content::WebContents* web_contents = function_->GetSenderWebContents();
60 Profile* profile = Profile::FromBrowserContext( 60 Profile* profile = Profile::FromBrowserContext(
61 function_->render_frame_host()->GetProcess()->GetBrowserContext()); 61 web_contents ? web_contents->GetBrowserContext()
62 Browser* browser = 62 : function_->browser_context());
63 chrome::FindAnyBrowser(profile, function_->include_incognito()); 63 Browser* browser =
64 if (browser) 64 chrome::FindAnyBrowser(profile, function_->include_incognito());
65 return browser; 65 if (browser)
66 } 66 return browser;
67 67
68 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, 68 // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
69 // a background_page onload chrome.tabs api call can make it into here 69 // a background_page onload chrome.tabs api call can make it into here
70 // before the browser is sufficiently initialized to return here, or 70 // before the browser is sufficiently initialized to return here, or
71 // all of this profile's browser windows may have been closed. 71 // all of this profile's browser windows may have been closed.
72 // A similar situation may arise during shutdown. 72 // A similar situation may arise during shutdown.
73 // TODO(rafaelw): Delay creation of background_page until the browser 73 // TODO(rafaelw): Delay creation of background_page until the browser
74 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 74 // is available. http://code.google.com/p/chromium/issues/detail?id=13284
75 return NULL; 75 return NULL;
76 } 76 }
77 77
78 extensions::WindowController* 78 extensions::WindowController*
79 ChromeExtensionFunctionDetails::GetExtensionWindowController() const { 79 ChromeExtensionFunctionDetails::GetExtensionWindowController() const {
80 // If the delegate has an associated window controller, return it. 80 // If the delegate has an associated window controller, return it.
81 if (function_->dispatcher()) { 81 if (function_->dispatcher()) {
82 extensions::WindowController* window_controller = 82 extensions::WindowController* window_controller =
83 function_->dispatcher()->GetExtensionWindowController(); 83 function_->dispatcher()->GetExtensionWindowController();
84 if (window_controller) 84 if (window_controller)
85 return window_controller; 85 return window_controller;
86 } 86 }
87 87
88 return extensions::WindowControllerList::GetInstance() 88 return extensions::WindowControllerList::GetInstance()
89 ->CurrentWindowForFunction(function_); 89 ->CurrentWindowForFunction(function_);
90 } 90 }
91 91
92 content::WebContents* 92 content::WebContents*
93 ChromeExtensionFunctionDetails::GetAssociatedWebContents() { 93 ChromeExtensionFunctionDetails::GetAssociatedWebContents() {
94 content::WebContents* web_contents = function_->GetAssociatedWebContents(); 94 if (function_->dispatcher()) {
lazyboy 2016/08/31 20:48:24 Feels a bit odd that function::GetAssocWC goes fro
Devlin 2016/08/31 20:56:39 Agreed - but it seems better than having 100% dupl
lazyboy 2016/08/31 21:21:42 Acknowledged.
95 if (web_contents) 95 content::WebContents* web_contents =
96 return web_contents; 96 function_->dispatcher()->GetAssociatedWebContents();
97 if (web_contents)
98 return web_contents;
99 }
97 100
98 Browser* browser = GetCurrentBrowser(); 101 Browser* browser = GetCurrentBrowser();
99 if (!browser) 102 if (!browser)
100 return NULL; 103 return NULL;
101 return browser->tab_strip_model()->GetActiveWebContents(); 104 return browser->tab_strip_model()->GetActiveWebContents();
102 } 105 }
103 106
104 content::WebContents* ChromeExtensionFunctionDetails::GetOriginWebContents() { 107 content::WebContents* ChromeExtensionFunctionDetails::GetOriginWebContents() {
105 WebContents* contents = function_->GetSenderWebContents(); 108 WebContents* contents = function_->GetSenderWebContents();
106 if (!contents) 109 if (!contents)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return controller->window()->GetNativeWindow(); 154 return controller->window()->GetNativeWindow();
152 155
153 // CurrentWindowForFunction() can't find app's window. 156 // CurrentWindowForFunction() can't find app's window.
154 WebContents* contents = GetOriginWebContents(); 157 WebContents* contents = GetOriginWebContents();
155 if (contents) 158 if (contents)
156 return contents->GetTopLevelNativeWindow(); 159 return contents->GetTopLevelNativeWindow();
157 160
158 Browser* browser = chrome::FindBrowserWithProfile(GetProfile()); 161 Browser* browser = chrome::FindBrowserWithProfile(GetProfile());
159 return browser->window()->GetNativeWindow(); 162 return browser->window()->GetNativeWindow();
160 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698