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 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/memory/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "chrome/browser/printing/print_view_manager.h" | 12 #include "chrome/browser/printing/print_view_manager.h" |
13 #include "chrome/browser/sessions/session_id.h" | 13 #include "chrome/browser/sessions/session_id.h" |
14 #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" | 15 #include "chrome/browser/ui/cocoa/applescript/apple_event_util.h" |
16 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" | 16 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" |
17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
18 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
19 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 @implementation TabAppleScript | 54 @implementation TabAppleScript |
55 | 55 |
56 @synthesize tempURL = tempURL_; | 56 @synthesize tempURL = tempURL_; |
57 | 57 |
58 - (id)init { | 58 - (id)init { |
59 if ((self = [super init])) { | 59 if ((self = [super init])) { |
60 SessionID session; | 60 SessionID session; |
61 SessionID::id_type futureSessionIDOfTab = session.id() + 1; | 61 SessionID::id_type futureSessionIDOfTab = session.id() + 1; |
62 // Holds the SessionID that the new tab is going to get. | 62 // Holds the SessionID that the new tab is going to get. |
63 scoped_nsobject<NSNumber> numID( | 63 base::scoped_nsobject<NSNumber> numID( |
64 [[NSNumber alloc] initWithInt:futureSessionIDOfTab]); | 64 [[NSNumber alloc] initWithInt:futureSessionIDOfTab]); |
65 [self setUniqueID:numID]; | 65 [self setUniqueID:numID]; |
66 } | 66 } |
67 return self; | 67 return self; |
68 } | 68 } |
69 | 69 |
70 - (void)dealloc { | 70 - (void)dealloc { |
71 [tempURL_ release]; | 71 [tempURL_ release]; |
72 [super dealloc]; | 72 [super dealloc]; |
73 } | 73 } |
74 | 74 |
75 - (id)initWithWebContents:(content::WebContents*)webContents { | 75 - (id)initWithWebContents:(content::WebContents*)webContents { |
76 if (!webContents) { | 76 if (!webContents) { |
77 [self release]; | 77 [self release]; |
78 return nil; | 78 return nil; |
79 } | 79 } |
80 | 80 |
81 if ((self = [super init])) { | 81 if ((self = [super init])) { |
82 // It is safe to be weak; if a tab goes away (e.g. the user closes a tab) | 82 // It is safe to be weak; if a tab goes away (e.g. the user closes a tab) |
83 // the AppleScript runtime calls tabs in AppleScriptWindow and this | 83 // the AppleScript runtime calls tabs in AppleScriptWindow and this |
84 // particular tab is never returned. | 84 // particular tab is never returned. |
85 webContents_ = webContents; | 85 webContents_ = webContents; |
86 SessionTabHelper* session_tab_helper = | 86 SessionTabHelper* session_tab_helper = |
87 SessionTabHelper::FromWebContents(webContents); | 87 SessionTabHelper::FromWebContents(webContents); |
88 scoped_nsobject<NSNumber> numID( | 88 base::scoped_nsobject<NSNumber> numID( |
89 [[NSNumber alloc] initWithInt:session_tab_helper->session_id().id()]); | 89 [[NSNumber alloc] initWithInt:session_tab_helper->session_id().id()]); |
90 [self setUniqueID:numID]; | 90 [self setUniqueID:numID]; |
91 } | 91 } |
92 return self; | 92 return self; |
93 } | 93 } |
94 | 94 |
95 - (void)setWebContents:(content::WebContents*)webContents { | 95 - (void)setWebContents:(content::WebContents*)webContents { |
96 DCHECK(webContents); | 96 DCHECK(webContents); |
97 // It is safe to be weak; if a tab goes away (e.g. the user closes a tab) | 97 // It is safe to be weak; if a tab goes away (e.g. the user closes a tab) |
98 // the AppleScript runtime calls tabs in AppleScriptWindow and this | 98 // the AppleScript runtime calls tabs in AppleScriptWindow and this |
99 // particular tab is never returned. | 99 // particular tab is never returned. |
100 webContents_ = webContents; | 100 webContents_ = webContents; |
101 SessionTabHelper* session_tab_helper = | 101 SessionTabHelper* session_tab_helper = |
102 SessionTabHelper::FromWebContents(webContents); | 102 SessionTabHelper::FromWebContents(webContents); |
103 scoped_nsobject<NSNumber> numID( | 103 base::scoped_nsobject<NSNumber> numID( |
104 [[NSNumber alloc] initWithInt:session_tab_helper->session_id().id()]); | 104 [[NSNumber alloc] initWithInt:session_tab_helper->session_id().id()]); |
105 [self setUniqueID:numID]; | 105 [self setUniqueID:numID]; |
106 | 106 |
107 if ([self tempURL]) | 107 if ([self tempURL]) |
108 [self setURL:[self tempURL]]; | 108 [self setURL:[self tempURL]]; |
109 } | 109 } |
110 | 110 |
111 - (NSString*)URL { | 111 - (NSString*)URL { |
112 if (!webContents_) { | 112 if (!webContents_) { |
113 return nil; | 113 return nil; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 string16 script = base::SysNSStringToUTF16( | 330 string16 script = base::SysNSStringToUTF16( |
331 [[command evaluatedArguments] objectForKey:@"javascript"]); | 331 [[command evaluatedArguments] objectForKey:@"javascript"]); |
332 view->ExecuteJavascriptInWebFrameCallbackResult(string16(), // frame_xpath | 332 view->ExecuteJavascriptInWebFrameCallbackResult(string16(), // frame_xpath |
333 script, | 333 script, |
334 callback); | 334 callback); |
335 | 335 |
336 return nil; | 336 return nil; |
337 } | 337 } |
338 | 338 |
339 @end | 339 @end |
OLD | NEW |