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

Side by Side Diff: chrome/browser/cocoa/extensions/browser_actions_controller.mm

Issue 402077: Adds popups to browser actions, completing the feature.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #import "browser_actions_controller.h" 5 #import "browser_actions_controller.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/gfx/canvas_paint.h" 9 #include "app/gfx/canvas_paint.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
11 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
12 #include "chrome/browser/cocoa/extensions/extension_popup_controller.h"
12 #include "chrome/browser/cocoa/toolbar_button_cell.h" 13 #include "chrome/browser/cocoa/toolbar_button_cell.h"
13 #include "chrome/browser/extensions/extension_browser_event_router.h" 14 #include "chrome/browser/extensions/extension_browser_event_router.h"
14 #include "chrome/browser/extensions/extensions_service.h" 15 #include "chrome/browser/extensions/extensions_service.h"
15 #include "chrome/browser/extensions/extension_tabs_module.h" 16 #include "chrome/browser/extensions/extension_tabs_module.h"
16 #include "chrome/browser/extensions/image_loading_tracker.h" 17 #include "chrome/browser/extensions/image_loading_tracker.h"
17 #include "chrome/browser/profile.h" 18 #include "chrome/browser/profile.h"
18 #include "chrome/browser/tab_contents/tab_contents.h" 19 #include "chrome/browser/tab_contents/tab_contents.h"
19 #include "chrome/common/notification_observer.h" 20 #include "chrome/common/notification_observer.h"
20 #include "chrome/common/notification_registrar.h" 21 #include "chrome/common/notification_registrar.h"
21 #include "skia/ext/skia_utils_mac.h" 22 #include "skia/ext/skia_utils_mac.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 break; 272 break;
272 } 273 }
273 case NotificationType::EXTENSION_UNLOADED: 274 case NotificationType::EXTENSION_UNLOADED:
274 case NotificationType::EXTENSION_UNLOADED_DISABLED: { 275 case NotificationType::EXTENSION_UNLOADED_DISABLED: {
275 Extension* extension = Details<Extension>(details).ptr(); 276 Extension* extension = Details<Extension>(details).ptr();
276 [owner_ removeActionButtonForExtension:extension]; 277 [owner_ removeActionButtonForExtension:extension];
277 [owner_ browserActionVisibilityHasChanged]; 278 [owner_ browserActionVisibilityHasChanged];
278 break; 279 break;
279 } 280 }
280 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: 281 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE:
281 //if (Details<ExtensionHost>(popup_->host()) != details) 282 if (Details<ExtensionHost>([[owner_ popup] host]) != details)
282 // return; 283 return;
283 [owner_ hidePopup]; 284 [owner_ hidePopup];
284 break; 285 break;
285 default: 286 default:
286 NOTREACHED() << L"Unexpected notification"; 287 NOTREACHED() << L"Unexpected notification";
287 } 288 }
288 } 289 }
289 290
290 private: 291 private:
291 // The object we need to inform when we get a notification. Weak. Owns us. 292 // The object we need to inform when we get a notification. Weak. Owns us.
292 BrowserActionsController* owner_; 293 BrowserActionsController* owner_;
(...skipping 18 matching lines...) Expand all
311 [containerView_ setHidden:YES]; 312 [containerView_ setHidden:YES];
312 observer_.reset(new ExtensionsServiceObserverBridge(self, profile_)); 313 observer_.reset(new ExtensionsServiceObserverBridge(self, profile_));
313 buttons_.reset([[NSMutableDictionary alloc] init]); 314 buttons_.reset([[NSMutableDictionary alloc] init]);
314 buttonOrder_.reset([[NSMutableArray alloc] init]); 315 buttonOrder_.reset([[NSMutableArray alloc] init]);
315 } 316 }
316 317
317 return self; 318 return self;
318 } 319 }
319 320
320 - (void)hidePopup { 321 - (void)hidePopup {
321 NOTIMPLEMENTED(); 322 [popupController_ close];
323 popupController_ = nil;
324 }
325
326 - (ExtensionPopupController*)popup {
327 return popupController_;
322 } 328 }
323 329
324 - (void)browserActionVisibilityHasChanged { 330 - (void)browserActionVisibilityHasChanged {
325 [containerView_ setNeedsDisplay:YES]; 331 [containerView_ setNeedsDisplay:YES];
326 } 332 }
327 333
328 - (void)createButtons { 334 - (void)createButtons {
329 ExtensionsService* extensionsService = profile_->GetExtensionsService(); 335 ExtensionsService* extensionsService = profile_->GetExtensionsService();
330 if (!extensionsService) // |extensionsService| can be NULL in Incognito. 336 if (!extensionsService) // |extensionsService| can be NULL in Incognito.
331 return; 337 return;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 401 }
396 } 402 }
397 403
398 - (int)buttonCount { 404 - (int)buttonCount {
399 return [buttons_ count]; 405 return [buttons_ count];
400 } 406 }
401 407
402 - (void)browserActionClicked:(BrowserActionButton*)sender { 408 - (void)browserActionClicked:(BrowserActionButton*)sender {
403 ExtensionAction* action = [sender extension]->browser_action(); 409 ExtensionAction* action = [sender extension]->browser_action();
404 if (action->has_popup()) { 410 if (action->has_popup()) {
405 // Popups are not implemented for Mac yet. 411 NSString* extensionId = base::SysUTF8ToNSString([sender extension]->id());
406 NOTIMPLEMENTED(); 412 // If the extension ID is not valid UTF-8, then the NSString will be nil
413 // and an exception will be thrown when calling objectForKey below, hosing
414 // the browser. Check it.
415 DCHECK(extensionId);
416 if (!extensionId)
417 return;
418 BrowserActionButton* actionButton = [buttons_ objectForKey:extensionId];
419 NSRect relativeButtonBounds = [[[actionButton window] contentView]
420 convertRect:[actionButton bounds]
421 fromView:actionButton];
422 NSPoint arrowPoint = [[actionButton window] convertBaseToScreen:NSMakePoint(
423 NSMinX(relativeButtonBounds),
424 NSMinY(relativeButtonBounds))];
425 // Adjust the anchor point to be at the center of the browser action button.
426 arrowPoint.x += kBrowserActionWidth / 2;
427
428 popupController_ =
429 [[ExtensionPopupController showURL:action->popup_url()
430 inBrowser:browser_
431 anchoredAt:arrowPoint
432 arrowLocation:kTopRight] retain];
407 } else { 433 } else {
408 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( 434 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted(
409 profile_, action->extension_id(), browser_); 435 profile_, action->extension_id(), browser_);
410 } 436 }
411 } 437 }
412 438
413 - (int)currentTabId { 439 - (int)currentTabId {
414 TabContents* selected_tab = browser_->GetSelectedTabContents(); 440 TabContents* selected_tab = browser_->GetSelectedTabContents();
415 if (!selected_tab) 441 if (!selected_tab)
416 return -1; 442 return -1;
417 443
418 return selected_tab->controller().session_id().id(); 444 return selected_tab->controller().session_id().id();
419 } 445 }
420 446
421 @end 447 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698