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

Side by Side Diff: chrome/browser/ui/intents/web_intent_picker_controller.cc

Issue 9649020: [Web Intents] WebIntentPickerModel uses URL instead of index to reference registered services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mac fix Created 8 years, 9 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 | Annotate | Revision Log
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 "chrome/browser/ui/intents/web_intent_picker_controller.h" 5 #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
6 6
7 #include <vector> 7 #include <vector>
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 void WebIntentPickerController::Observe( 142 void WebIntentPickerController::Observe(
143 int type, 143 int type,
144 const content::NotificationSource& source, 144 const content::NotificationSource& source,
145 const content::NotificationDetails& details) { 145 const content::NotificationDetails& details) {
146 DCHECK(type == content::NOTIFICATION_LOAD_START || 146 DCHECK(type == content::NOTIFICATION_LOAD_START ||
147 type == content::NOTIFICATION_TAB_CLOSING); 147 type == content::NOTIFICATION_TAB_CLOSING);
148 ClosePicker(); 148 ClosePicker();
149 } 149 }
150 150
151 void WebIntentPickerController::OnServiceChosen(size_t index, 151 void WebIntentPickerController::OnServiceChosen(const GURL& url,
152 Disposition disposition) { 152 Disposition disposition) {
153 switch (disposition) { 153 switch (disposition) {
154 case WebIntentPickerModel::DISPOSITION_INLINE: 154 case WebIntentPickerModel::DISPOSITION_INLINE:
155 // Set the model to inline disposition. It will notify the picker which 155 // Set the model to inline disposition. It will notify the picker which
156 // will respond (via OnInlineDispositionWebContentsCreated) with the 156 // will respond (via OnInlineDispositionWebContentsCreated) with the
157 // WebContents to dispatch the intent to. 157 // WebContents to dispatch the intent to.
158 picker_model_->SetInlineDisposition(index); 158 picker_model_->SetInlineDisposition(url);
159 break; 159 break;
160 160
161 case WebIntentPickerModel::DISPOSITION_WINDOW: { 161 case WebIntentPickerModel::DISPOSITION_WINDOW: {
162 // TODO(gbillock): This really only handles the 'window' disposition in a 162 // TODO(gbillock): This really only handles the 'window' disposition in a
163 // quite prototype way. We need to flesh out what happens to the picker 163 // quite prototype way. We need to flesh out what happens to the picker
164 // during the lifetime of the service url context, and that may mean we 164 // during the lifetime of the service url context, and that may mean we
165 // need to pass more information into the injector to find the picker 165 // need to pass more information into the injector to find the picker
166 // again and close it. 166 // again and close it.
167 const WebIntentPickerModel::InstalledService& installed_service =
168 picker_model_->GetInstalledServiceAt(index);
169
170 int index = TabStripModel::kNoTab; 167 int index = TabStripModel::kNoTab;
171 Browser* browser = Browser::GetBrowserForController( 168 Browser* browser = Browser::GetBrowserForController(
172 &wrapper_->web_contents()->GetController(), &index); 169 &wrapper_->web_contents()->GetController(), &index);
173 TabContentsWrapper* contents = Browser::TabContentsFactory( 170 TabContentsWrapper* contents = Browser::TabContentsFactory(
174 browser->profile(), 171 browser->profile(),
175 tab_util::GetSiteInstanceForNewTab( 172 tab_util::GetSiteInstanceForNewTab(
176 NULL, browser->profile(), installed_service.url), 173 NULL, browser->profile(), url),
177 MSG_ROUTING_NONE, NULL, NULL); 174 MSG_ROUTING_NONE, NULL, NULL);
178 175
179 intents_dispatcher_->DispatchIntent(contents->web_contents()); 176 intents_dispatcher_->DispatchIntent(contents->web_contents());
180 service_tab_ = contents->web_contents(); 177 service_tab_ = contents->web_contents();
181 178
182 // This call performs all the tab strip manipulation, notifications, etc. 179 // This call performs all the tab strip manipulation, notifications, etc.
183 // Since we're passing in a target_contents, it assumes that we will 180 // Since we're passing in a target_contents, it assumes that we will
184 // navigate the page ourselves, though. 181 // navigate the page ourselves, though.
185 browser::NavigateParams params(browser, 182 browser::NavigateParams params(browser,
186 installed_service.url, 183 url,
187 content::PAGE_TRANSITION_AUTO_BOOKMARK); 184 content::PAGE_TRANSITION_AUTO_BOOKMARK);
188 params.target_contents = contents; 185 params.target_contents = contents;
189 params.disposition = NEW_FOREGROUND_TAB; 186 params.disposition = NEW_FOREGROUND_TAB;
190 params.profile = wrapper_->profile(); 187 params.profile = wrapper_->profile();
191 browser::Navigate(&params); 188 browser::Navigate(&params);
192 189
193 service_tab_->GetController().LoadURL( 190 service_tab_->GetController().LoadURL(
194 installed_service.url, content::Referrer(), 191 url, content::Referrer(),
195 content::PAGE_TRANSITION_AUTO_BOOKMARK, std::string()); 192 content::PAGE_TRANSITION_AUTO_BOOKMARK, std::string());
196 193
197 ClosePicker(); 194 ClosePicker();
198 break; 195 break;
199 } 196 }
200 197
201 default: 198 default:
202 NOTREACHED(); 199 NOTREACHED();
203 break; 200 break;
204 } 201 }
205 } 202 }
206 203
207 void WebIntentPickerController::OnInlineDispositionWebContentsCreated( 204 void WebIntentPickerController::OnInlineDispositionWebContentsCreated(
208 content::WebContents* web_contents) { 205 content::WebContents* web_contents) {
209 if (web_contents) { 206 if (web_contents)
210 intents_dispatcher_->DispatchIntent(web_contents); 207 intents_dispatcher_->DispatchIntent(web_contents);
211 } else {
212 // TODO(binji): web_contents should never be NULL; it is in this case
213 // because views doesn't have an implementation for inline disposition yet.
214 // Remove this else when it does. In the meantime, just reforward as if it
215 // were the window disposition.
216 OnServiceChosen(picker_model_->inline_disposition_index(),
217 WebIntentPickerModel::DISPOSITION_WINDOW);
218 }
219 } 208 }
220 209
221 void WebIntentPickerController::OnCancelled() { 210 void WebIntentPickerController::OnCancelled() {
222 if (!intents_dispatcher_) 211 if (!intents_dispatcher_)
223 return; 212 return;
224 213
225 if (service_tab_) { 214 if (service_tab_) {
226 intents_dispatcher_->SendReplyMessage( 215 intents_dispatcher_->SendReplyMessage(
227 webkit_glue::WEB_INTENT_SERVICE_TAB_CLOSED, string16()); 216 webkit_glue::WEB_INTENT_SERVICE_TAB_CLOSED, string16());
228 } else { 217 } else {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (--pending_async_count_ == 0) { 421 if (--pending_async_count_ == 0) {
433 picker_->OnPendingAsyncCompleted(); 422 picker_->OnPendingAsyncCompleted();
434 } 423 }
435 } 424 }
436 425
437 void WebIntentPickerController::ClosePicker() { 426 void WebIntentPickerController::ClosePicker() {
438 if (picker_) { 427 if (picker_) {
439 picker_->Close(); 428 picker_->Close();
440 } 429 }
441 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698