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

Side by Side Diff: chrome/browser/ui/extensions/extension_action_view_controller.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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/ui/extensions/extension_action_view_controller.h" 5 #include "chrome/browser/ui/extensions/extension_action_view_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 275
276 CommandService* command_service = CommandService::Get(browser_->profile()); 276 CommandService* command_service = CommandService::Get(browser_->profile());
277 if (extension_action_->action_type() == ActionInfo::TYPE_PAGE) { 277 if (extension_action_->action_type() == ActionInfo::TYPE_PAGE) {
278 return command_service->GetPageActionCommand( 278 return command_service->GetPageActionCommand(
279 extension_->id(), CommandService::ACTIVE, command, NULL); 279 extension_->id(), CommandService::ACTIVE, command, NULL);
280 } 280 }
281 return command_service->GetBrowserActionCommand( 281 return command_service->GetBrowserActionCommand(
282 extension_->id(), CommandService::ACTIVE, command, NULL); 282 extension_->id(), CommandService::ACTIVE, command, NULL);
283 } 283 }
284 284
285 scoped_ptr<IconWithBadgeImageSource> 285 std::unique_ptr<IconWithBadgeImageSource>
286 ExtensionActionViewController::GetIconImageSourceForTesting( 286 ExtensionActionViewController::GetIconImageSourceForTesting(
287 content::WebContents* web_contents, 287 content::WebContents* web_contents,
288 const gfx::Size& size) { 288 const gfx::Size& size) {
289 return GetIconImageSource(web_contents, size); 289 return GetIconImageSource(web_contents, size);
290 } 290 }
291 291
292 ExtensionActionViewController* 292 ExtensionActionViewController*
293 ExtensionActionViewController::GetPreferredPopupViewController() { 293 ExtensionActionViewController::GetPreferredPopupViewController() {
294 if (toolbar_actions_bar_ && toolbar_actions_bar_->in_overflow_mode()) { 294 if (toolbar_actions_bar_ && toolbar_actions_bar_->in_overflow_mode()) {
295 return static_cast<ExtensionActionViewController*>( 295 return static_cast<ExtensionActionViewController*>(
(...skipping 15 matching lines...) Expand all
311 // Always hide the current popup, even if it's not owned by this extension. 311 // Always hide the current popup, even if it's not owned by this extension.
312 // Only one popup should be visible at a time. 312 // Only one popup should be visible at a time.
313 HideActivePopup(); 313 HideActivePopup();
314 314
315 // If we were showing a popup already, then we treat the action to open the 315 // If we were showing a popup already, then we treat the action to open the
316 // same one as a desire to close it (like clicking a menu button that was 316 // same one as a desire to close it (like clicking a menu button that was
317 // already open). 317 // already open).
318 if (already_showing) 318 if (already_showing)
319 return false; 319 return false;
320 320
321 scoped_ptr<extensions::ExtensionViewHost> host( 321 std::unique_ptr<extensions::ExtensionViewHost> host(
322 extensions::ExtensionViewHostFactory::CreatePopupHost(popup_url, 322 extensions::ExtensionViewHostFactory::CreatePopupHost(popup_url,
323 browser_)); 323 browser_));
324 if (!host) 324 if (!host)
325 return false; 325 return false;
326 326
327 popup_host_ = host.get(); 327 popup_host_ = host.get();
328 popup_host_observer_.Add(popup_host_); 328 popup_host_observer_.Add(popup_host_);
329 if (toolbar_actions_bar_) 329 if (toolbar_actions_bar_)
330 toolbar_actions_bar_->SetPopupOwner(this); 330 toolbar_actions_bar_->SetPopupOwner(this);
331 331
332 if (toolbar_actions_bar_ && 332 if (toolbar_actions_bar_ &&
333 !toolbar_actions_bar_->IsActionVisibleOnMainBar(this) && 333 !toolbar_actions_bar_->IsActionVisibleOnMainBar(this) &&
334 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { 334 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) {
335 platform_delegate_->CloseOverflowMenu(); 335 platform_delegate_->CloseOverflowMenu();
336 toolbar_actions_bar_->PopOutAction( 336 toolbar_actions_bar_->PopOutAction(
337 this, 337 this,
338 show_action == SHOW_POPUP_AND_INSPECT, 338 show_action == SHOW_POPUP_AND_INSPECT,
339 base::Bind(&ExtensionActionViewController::ShowPopup, 339 base::Bind(&ExtensionActionViewController::ShowPopup,
340 weak_factory_.GetWeakPtr(), base::Passed(std::move(host)), 340 weak_factory_.GetWeakPtr(), base::Passed(std::move(host)),
341 grant_tab_permissions, show_action)); 341 grant_tab_permissions, show_action));
342 } else { 342 } else {
343 ShowPopup(std::move(host), grant_tab_permissions, show_action); 343 ShowPopup(std::move(host), grant_tab_permissions, show_action);
344 } 344 }
345 345
346 return true; 346 return true;
347 } 347 }
348 348
349 void ExtensionActionViewController::ShowPopup( 349 void ExtensionActionViewController::ShowPopup(
350 scoped_ptr<extensions::ExtensionViewHost> popup_host, 350 std::unique_ptr<extensions::ExtensionViewHost> popup_host,
351 bool grant_tab_permissions, 351 bool grant_tab_permissions,
352 PopupShowAction show_action) { 352 PopupShowAction show_action) {
353 // It's possible that the popup should be closed before it finishes opening 353 // It's possible that the popup should be closed before it finishes opening
354 // (since it can open asynchronously). Check before proceeding. 354 // (since it can open asynchronously). Check before proceeding.
355 if (!popup_host_) 355 if (!popup_host_)
356 return; 356 return;
357 platform_delegate_->ShowPopup(std::move(popup_host), grant_tab_permissions, 357 platform_delegate_->ShowPopup(std::move(popup_host), grant_tab_permissions,
358 show_action); 358 show_action);
359 view_delegate_->OnPopupShown(grant_tab_permissions); 359 view_delegate_->OnPopupShown(grant_tab_permissions);
360 } 360 }
361 361
362 void ExtensionActionViewController::OnPopupClosed() { 362 void ExtensionActionViewController::OnPopupClosed() {
363 popup_host_observer_.Remove(popup_host_); 363 popup_host_observer_.Remove(popup_host_);
364 popup_host_ = nullptr; 364 popup_host_ = nullptr;
365 if (toolbar_actions_bar_) { 365 if (toolbar_actions_bar_) {
366 toolbar_actions_bar_->SetPopupOwner(nullptr); 366 toolbar_actions_bar_->SetPopupOwner(nullptr);
367 if (toolbar_actions_bar_->popped_out_action() == this && 367 if (toolbar_actions_bar_->popped_out_action() == this &&
368 !view_delegate_->IsMenuRunning()) 368 !view_delegate_->IsMenuRunning())
369 toolbar_actions_bar_->UndoPopOut(); 369 toolbar_actions_bar_->UndoPopOut();
370 } 370 }
371 view_delegate_->OnPopupClosed(); 371 view_delegate_->OnPopupClosed();
372 } 372 }
373 373
374 scoped_ptr<IconWithBadgeImageSource> 374 std::unique_ptr<IconWithBadgeImageSource>
375 ExtensionActionViewController::GetIconImageSource( 375 ExtensionActionViewController::GetIconImageSource(
376 content::WebContents* web_contents, 376 content::WebContents* web_contents,
377 const gfx::Size& size) { 377 const gfx::Size& size) {
378 int tab_id = SessionTabHelper::IdForTab(web_contents); 378 int tab_id = SessionTabHelper::IdForTab(web_contents);
379 scoped_ptr<IconWithBadgeImageSource> image_source( 379 std::unique_ptr<IconWithBadgeImageSource> image_source(
380 new IconWithBadgeImageSource(size)); 380 new IconWithBadgeImageSource(size));
381 381
382 image_source->SetIcon(icon_factory_.GetIcon(tab_id)); 382 image_source->SetIcon(icon_factory_.GetIcon(tab_id));
383 383
384 scoped_ptr<IconWithBadgeImageSource::Badge> badge; 384 std::unique_ptr<IconWithBadgeImageSource::Badge> badge;
385 std::string badge_text = extension_action_->GetBadgeText(tab_id); 385 std::string badge_text = extension_action_->GetBadgeText(tab_id);
386 if (!badge_text.empty()) { 386 if (!badge_text.empty()) {
387 badge.reset(new IconWithBadgeImageSource::Badge( 387 badge.reset(new IconWithBadgeImageSource::Badge(
388 badge_text, 388 badge_text,
389 extension_action_->GetBadgeTextColor(tab_id), 389 extension_action_->GetBadgeTextColor(tab_id),
390 extension_action_->GetBadgeBackgroundColor(tab_id))); 390 extension_action_->GetBadgeBackgroundColor(tab_id)));
391 } 391 }
392 image_source->SetBadge(std::move(badge)); 392 image_source->SetBadge(std::move(badge));
393 393
394 // Greyscaling disabled actions and having a special wants-to-run decoration 394 // Greyscaling disabled actions and having a special wants-to-run decoration
(...skipping 26 matching lines...) Expand all
421 extension_action_->GetIsVisible( 421 extension_action_->GetIsVisible(
422 SessionTabHelper::IdForTab(web_contents)); 422 SessionTabHelper::IdForTab(web_contents));
423 } 423 }
424 424
425 bool ExtensionActionViewController::HasBeenBlocked( 425 bool ExtensionActionViewController::HasBeenBlocked(
426 content::WebContents* web_contents) const { 426 content::WebContents* web_contents) const {
427 ExtensionActionRunner* action_runner = 427 ExtensionActionRunner* action_runner =
428 ExtensionActionRunner::GetForWebContents(web_contents); 428 ExtensionActionRunner::GetForWebContents(web_contents);
429 return action_runner && action_runner->WantsToRun(extension()); 429 return action_runner && action_runner->WantsToRun(extension());
430 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698