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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/location_bar/content_setting_decoration.mm
diff --git a/chrome/browser/cocoa/location_bar/content_setting_decoration.mm b/chrome/browser/cocoa/location_bar/content_setting_decoration.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6f2b8a3935406a8af5a6bb263c88be5fabb425f7
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar/content_setting_decoration.mm
@@ -0,0 +1,88 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/location_bar/content_setting_decoration.h"
+
+#include "app/resource_bundle.h"
+#include "base/sys_string_conversions.h"
+#include "chrome/browser/browser_list.h"
+#import "chrome/browser/cocoa/content_blocked_bubble_controller.h"
+#import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
+#include "chrome/browser/content_setting_image_model.h"
+#include "chrome/browser/content_setting_bubble_model.h"
+#include "chrome/browser/pref_service.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/pref_names.h"
+#include "net/base/net_util.h"
+
+ContentSettingDecoration::ContentSettingDecoration(
+ ContentSettingsType settings_type,
+ LocationBarViewMac* owner,
+ Profile* profile)
+ : content_setting_image_model_(
+ ContentSettingImageModel::CreateContentSettingImageModel(
+ settings_type)),
+ owner_(owner),
+ profile_(profile) {
+}
+
+ContentSettingDecoration::~ContentSettingDecoration() {
+}
+
+void ContentSettingDecoration::UpdateFromTabContents(
+ const TabContents* tab_contents) {
+ content_setting_image_model_->UpdateFromTabContents(tab_contents);
+ SetVisible(content_setting_image_model_->is_visible());
+ if (IsVisible()) {
+ // TODO(thakis): We should use pdfs for these icons on OSX.
+ // http://crbug.com/35847
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ SetImage(rb.GetNSImageNamed(content_setting_image_model_->get_icon()));
+ SetToolTip(base::SysUTF8ToNSString(
+ content_setting_image_model_->get_tooltip()));
+ }
+}
+
+bool ContentSettingDecoration::OnMousePressed(NSRect frame) {
+ // Get host. This should be shared on linux/win/osx medium-term.
+ TabContents* tabContents =
+ BrowserList::GetLastActive()->GetSelectedTabContents();
+ if (!tabContents)
+ return true;
+
+ GURL url = tabContents->GetURL();
+ std::wstring displayHost;
+ net::AppendFormattedHost(
+ url,
+ UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)),
+ &displayHost, NULL, NULL);
+
+ // Find point for bubble's arrow in screen coordinates.
+ // TODO(shess): |owner_| is only being used to fetch |field|.
+ // Consider passing in |control_view|.
+ AutocompleteTextField* field = owner_->GetAutocompleteTextField();
+ frame = GetDrawRectInFrame(frame);
+ NSPoint anchor = NSMakePoint(NSMidX(frame) + 1, NSMaxY(frame));
+ anchor = [field convertPoint:anchor toView:nil];
+ anchor = [[field window] convertBaseToScreen:anchor];
+
+ // Open bubble.
+ ContentSettingBubbleModel* model =
+ ContentSettingBubbleModel::CreateContentSettingBubbleModel(
+ tabContents, profile_,
+ content_setting_image_model_->get_content_settings_type());
+ [ContentBlockedBubbleController showForModel:model
+ parentWindow:[field window]
+ anchoredAt:anchor];
+ return true;
+}
+
+NSString* ContentSettingDecoration::GetToolTip() {
+ return tooltip_.get();
+}
+
+void ContentSettingDecoration::SetToolTip(NSString* tooltip) {
+ tooltip_.reset([tooltip retain]);
+}

Powered by Google App Engine
This is Rietveld 408576698