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

Side by Side Diff: chrome/browser/cocoa/location_bar/content_setting_decoration.mm

Issue 2888014: [Mac] Convert content settings to LocationBarDecoration, cleanup. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: noop change aiming for a clean try run. Created 10 years, 5 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
(Empty)
1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/location_bar/content_setting_decoration.h"
6
7 #include "app/resource_bundle.h"
8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/browser_list.h"
10 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h"
11 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
12 #include "chrome/browser/content_setting_image_model.h"
13 #include "chrome/browser/content_setting_bubble_model.h"
14 #include "chrome/browser/pref_service.h"
15 #include "chrome/browser/profile.h"
16 #include "chrome/browser/tab_contents/tab_contents.h"
17 #include "chrome/common/pref_names.h"
18 #include "net/base/net_util.h"
19
20 ContentSettingDecoration::ContentSettingDecoration(
21 ContentSettingsType settings_type,
22 LocationBarViewMac* owner,
23 Profile* profile)
24 : content_setting_image_model_(
25 ContentSettingImageModel::CreateContentSettingImageModel(
26 settings_type)),
27 owner_(owner),
28 profile_(profile) {
29 }
30
31 ContentSettingDecoration::~ContentSettingDecoration() {
32 }
33
34 void ContentSettingDecoration::UpdateFromTabContents(
35 const TabContents* tab_contents) {
36 content_setting_image_model_->UpdateFromTabContents(tab_contents);
37 SetVisible(content_setting_image_model_->is_visible());
38 if (IsVisible()) {
39 // TODO(thakis): We should use pdfs for these icons on OSX.
40 // http://crbug.com/35847
41 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
42 SetImage(rb.GetNSImageNamed(content_setting_image_model_->get_icon()));
43 SetToolTip(base::SysUTF8ToNSString(
44 content_setting_image_model_->get_tooltip()));
45 }
46 }
47
48 bool ContentSettingDecoration::OnMousePressed(NSRect frame) {
49 // Get host. This should be shared on linux/win/osx medium-term.
50 TabContents* tabContents =
51 BrowserList::GetLastActive()->GetSelectedTabContents();
52 if (!tabContents)
53 return true;
54
55 GURL url = tabContents->GetURL();
56 std::wstring displayHost;
57 net::AppendFormattedHost(
58 url,
59 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)),
60 &displayHost, NULL, NULL);
61
62 // Find point for bubble's arrow in screen coordinates.
63 // TODO(shess): |owner_| is only being used to fetch |field|.
64 // Consider passing in |control_view|.
65 AutocompleteTextField* field = owner_->GetAutocompleteTextField();
66 frame = GetDrawRectInFrame(frame);
67 NSPoint anchor = NSMakePoint(NSMidX(frame) + 1, NSMaxY(frame));
68 anchor = [field convertPoint:anchor toView:nil];
69 anchor = [[field window] convertBaseToScreen:anchor];
70
71 // Open bubble.
72 ContentSettingBubbleModel* model =
73 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
74 tabContents, profile_,
75 content_setting_image_model_->get_content_settings_type());
76 [ContentBlockedBubbleController showForModel:model
77 parentWindow:[field window]
78 anchoredAt:anchor];
79 return true;
80 }
81
82 NSString* ContentSettingDecoration::GetToolTip() {
83 return tooltip_.get();
84 }
85
86 void ContentSettingDecoration::SetToolTip(NSString* tooltip) {
87 tooltip_.reset([tooltip retain]);
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698