1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// Copyright (c) 2012 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.
#include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h"
#import <Cocoa/Cocoa.h>
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h"
#include "chrome/browser/ui/intents/web_intent_picker.h"
#include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "content/public/browser/web_contents.h"
#include "skia/ext/skia_utils_mac.h"
using content::WebContents;
class InlineHtmlContentDelegate: public content::WebContentsDelegate {
public:
InlineHtmlContentDelegate() {}
virtual ~InlineHtmlContentDelegate() {}
virtual bool IsPopupOrPanel(
const content::WebContents* source) const OVERRIDE {
return true;
}
virtual bool ShouldAddNavigationToHistory(
const history::HistoryAddPageArgs& add_page_args,
content::NavigationType navigation_type) OVERRIDE {
return false;
}
private:
DISALLOW_COPY_AND_ASSIGN(InlineHtmlContentDelegate);
};
// static
WebIntentPicker* WebIntentPicker::Create(Browser* browser,
TabContentsWrapper* wrapper,
WebIntentPickerDelegate* delegate) {
return new WebIntentPickerCocoa(browser, wrapper, delegate);
}
WebIntentPickerCocoa::WebIntentPickerCocoa()
: delegate_(NULL), browser_(NULL), controller_(NULL) {
}
WebIntentPickerCocoa::WebIntentPickerCocoa(Browser* browser,
TabContentsWrapper* wrapper,
WebIntentPickerDelegate* delegate)
: delegate_(delegate),
browser_(browser),
controller_(NULL) {
DCHECK(browser);
DCHECK(delegate);
NSWindow* parentWindow = browser->window()->GetNativeHandle();
// Compute the anchor point, relative to location bar.
BrowserWindowController* controller = [parentWindow windowController];
LocationBarViewMac* locationBar = [controller locationBarBridge];
NSPoint anchor = locationBar->GetPageInfoBubblePoint();
anchor = [browser->window()->GetNativeHandle() convertBaseToScreen:anchor];
// The controller is deallocated when the window is closed, so no need to
// worry about it here.
[[WebIntentBubbleController alloc] initWithPicker:this
parentWindow:parentWindow
anchoredAt:anchor];
}
void WebIntentPickerCocoa::SetServiceURLs(const std::vector<GURL>& urls) {
DCHECK(controller_);
scoped_nsobject<NSMutableArray> urlArray(
[[NSMutableArray alloc] initWithCapacity:urls.size()]);
for (std::vector<GURL>::const_iterator iter(urls.begin());
iter != urls.end(); ++iter) {
[urlArray addObject:
[NSString stringWithUTF8String:iter->spec().c_str()]];
}
[controller_ setServiceURLs:urlArray];
}
void WebIntentPickerCocoa::SetServiceIcon(size_t index, const SkBitmap& icon) {
DCHECK(controller_);
if (icon.empty())
return;
NSImage* image = gfx::SkBitmapToNSImage(icon);
[controller_ replaceImageAtIndex:index withImage:image];
}
void WebIntentPickerCocoa::SetDefaultServiceIcon(size_t index) {
}
void WebIntentPickerCocoa::Close() {
}
WebContents* WebIntentPickerCocoa::SetInlineDisposition(const GURL& url) {
WebContents* web_contents = WebContents::Create(
browser_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
inline_disposition_tab_contents_.reset(new TabContentsWrapper(web_contents));
inline_disposition_delegate_.reset(new InlineHtmlContentDelegate);
web_contents->SetDelegate(inline_disposition_delegate_.get());
inline_disposition_tab_contents_->web_contents()->GetController().LoadURL(
url,
content::Referrer(),
content::PAGE_TRANSITION_START_PAGE,
std::string());
[controller_ setInlineDispositionTabContents:
inline_disposition_tab_contents_.get()];
return inline_disposition_tab_contents_->web_contents();
}
WebIntentPickerCocoa::~WebIntentPickerCocoa() {
}
void WebIntentPickerCocoa::OnCancelled() {
DCHECK(delegate_);
delegate_->OnCancelled();
controller_ = NULL; // Controller will be unusable soon, abandon.
}
void WebIntentPickerCocoa::OnServiceChosen(size_t index) {
DCHECK(delegate_);
delegate_->OnServiceChosen(index);
}
void WebIntentPickerCocoa::set_controller(
WebIntentBubbleController* controller) {
controller_ = controller;
}
|