OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/applescript/tab_applescript.h" | 5 #import "chrome/browser/ui/cocoa/applescript/tab_applescript.h" |
6 | 6 |
7 #import <Carbon/Carbon.h> | |
8 #import <Foundation/NSAppleEventDescriptor.h> | |
9 | |
10 #include "base/bind.h" | 7 #include "base/bind.h" |
11 #include "base/file_path.h" | 8 #include "base/file_path.h" |
12 #include "base/logging.h" | 9 #include "base/logging.h" |
13 #import "base/memory/scoped_nsobject.h" | 10 #import "base/memory/scoped_nsobject.h" |
14 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
15 #include "base/utf_string_conversions.h" | |
16 #include "chrome/browser/printing/print_view_manager.h" | 12 #include "chrome/browser/printing/print_view_manager.h" |
17 #include "chrome/browser/sessions/session_id.h" | 13 #include "chrome/browser/sessions/session_id.h" |
18 #include "chrome/browser/sessions/session_tab_helper.h" | 14 #include "chrome/browser/sessions/session_tab_helper.h" |
| 15 #include "chrome/browser/ui/cocoa/applescript/apple_event_util.h" |
19 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" | 16 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" |
20 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
21 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
22 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
23 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
24 #include "content/public/browser/save_page_type.h" | 21 #include "content/public/browser/save_page_type.h" |
25 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
27 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
28 | 25 |
29 using content::NavigationController; | 26 using content::NavigationController; |
30 using content::NavigationEntry; | 27 using content::NavigationEntry; |
31 using content::OpenURLParams; | 28 using content::OpenURLParams; |
32 using content::RenderViewHost; | 29 using content::RenderViewHost; |
33 using content::Referrer; | 30 using content::Referrer; |
34 using content::WebContents; | 31 using content::WebContents; |
35 | 32 |
36 namespace { | 33 namespace { |
37 | 34 |
38 NSAppleEventDescriptor* valueToDescriptor(const base::Value* value) { | |
39 NSAppleEventDescriptor* descriptor = nil; | |
40 switch (value->GetType()) { | |
41 case base::Value::TYPE_NULL: | |
42 descriptor = [NSAppleEventDescriptor | |
43 descriptorWithTypeCode:cMissingValue]; | |
44 break; | |
45 case base::Value::TYPE_BOOLEAN: { | |
46 bool bool_value; | |
47 value->GetAsBoolean(&bool_value); | |
48 descriptor = [NSAppleEventDescriptor descriptorWithBoolean:bool_value]; | |
49 break; | |
50 } | |
51 case base::Value::TYPE_INTEGER: { | |
52 int int_value; | |
53 value->GetAsInteger(&int_value); | |
54 descriptor = [NSAppleEventDescriptor descriptorWithInt32:int_value]; | |
55 break; | |
56 } | |
57 case base::Value::TYPE_DOUBLE: { | |
58 double double_value; | |
59 value->GetAsDouble(&double_value); | |
60 descriptor = [NSAppleEventDescriptor | |
61 descriptorWithDescriptorType:typeIEEE64BitFloatingPoint | |
62 bytes:&double_value | |
63 length:sizeof(double_value)]; | |
64 break; | |
65 } | |
66 case base::Value::TYPE_STRING: { | |
67 std::string string_value; | |
68 value->GetAsString(&string_value); | |
69 descriptor = [NSAppleEventDescriptor descriptorWithString: | |
70 base::SysUTF8ToNSString(string_value)]; | |
71 break; | |
72 } | |
73 case base::Value::TYPE_BINARY: | |
74 NOTREACHED(); | |
75 break; | |
76 case base::Value::TYPE_DICTIONARY: { | |
77 const base::DictionaryValue* dictionary_value = | |
78 static_cast<const base::DictionaryValue*>(value); | |
79 descriptor = [NSAppleEventDescriptor recordDescriptor]; | |
80 NSAppleEventDescriptor* userRecord = [NSAppleEventDescriptor | |
81 listDescriptor]; | |
82 for (DictionaryValue::key_iterator iter(dictionary_value->begin_keys()); | |
83 iter != dictionary_value->end_keys(); ++iter) { | |
84 const base::Value* item; | |
85 if (dictionary_value->Get(*iter, &item)) { | |
86 [userRecord insertDescriptor:[NSAppleEventDescriptor | |
87 descriptorWithString:base::SysUTF8ToNSString(*iter)] atIndex:0]; | |
88 [userRecord insertDescriptor:valueToDescriptor(item) atIndex:0]; | |
89 } | |
90 } | |
91 // Description of what keyASUserRecordFields does. | |
92 // http://www.mail-archive.com/cocoa-dev%40lists.apple.com/msg40149.html | |
93 [descriptor setDescriptor:userRecord forKeyword:keyASUserRecordFields]; | |
94 break; | |
95 } | |
96 case base::Value::TYPE_LIST: { | |
97 const base::ListValue* list_value; | |
98 value->GetAsList(&list_value); | |
99 descriptor = [NSAppleEventDescriptor listDescriptor]; | |
100 for (unsigned i = 0; i < list_value->GetSize(); ++i) { | |
101 const base::Value* item; | |
102 list_value->Get(i, &item); | |
103 [descriptor insertDescriptor:valueToDescriptor(item) atIndex:0]; | |
104 } | |
105 break; | |
106 } | |
107 } | |
108 return descriptor; | |
109 } | |
110 | |
111 void ResumeAppleEventAndSendReply(NSAppleEventManagerSuspensionID suspension_id, | 35 void ResumeAppleEventAndSendReply(NSAppleEventManagerSuspensionID suspension_id, |
112 const base::Value* result_value) { | 36 const base::Value* result_value) { |
113 NSAppleEventDescriptor* result_descriptor = valueToDescriptor(result_value); | 37 NSAppleEventDescriptor* result_descriptor = |
| 38 ValueToAppleEventDescriptor(result_value); |
114 | 39 |
115 NSAppleEventManager* manager = [NSAppleEventManager sharedAppleEventManager]; | 40 NSAppleEventManager* manager = [NSAppleEventManager sharedAppleEventManager]; |
116 NSAppleEventDescriptor* reply_event = | 41 NSAppleEventDescriptor* reply_event = |
117 [manager replyAppleEventForSuspensionID:suspension_id]; | 42 [manager replyAppleEventForSuspensionID:suspension_id]; |
118 [reply_event setParamDescriptor:result_descriptor | 43 [reply_event setParamDescriptor:result_descriptor |
119 forKeyword:keyDirectObject]; | 44 forKeyword:keyDirectObject]; |
120 [manager resumeWithSuspensionID:suspension_id]; | 45 [manager resumeWithSuspensionID:suspension_id]; |
121 } | 46 } |
122 | 47 |
123 } // namespace | 48 } // namespace |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 string16 script = base::SysNSStringToUTF16( | 330 string16 script = base::SysNSStringToUTF16( |
406 [[command evaluatedArguments] objectForKey:@"javascript"]); | 331 [[command evaluatedArguments] objectForKey:@"javascript"]); |
407 view->ExecuteJavascriptInWebFrameCallbackResult(string16(), // frame_xpath | 332 view->ExecuteJavascriptInWebFrameCallbackResult(string16(), // frame_xpath |
408 script, | 333 script, |
409 callback); | 334 callback); |
410 | 335 |
411 return nil; | 336 return nil; |
412 } | 337 } |
413 | 338 |
414 @end | 339 @end |
OLD | NEW |